I try to use the cssembed filter loading my stylesheets (because of the images referenced in the css)
In config.yml
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ cramifviewkitBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
cssembed:
jar: %kernel.root_dir%/Resources/java/cssembed-0.4.5.jar
yui_css:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
yui_js:
jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
I download cssembed-0.4.5.jar and located it in src/my_bundle/Resources/java
in the template I wrote :
{% stylesheets
'#myBundle/Resources/public/css/*'
'#myBundle/Resources/public/JQMenu/css/*'
filter='cssembed'
%}
Everything is fine for the first import, but for the second one, when I look with firebug, I have this :
<link type="text/css" href="/viewkit/web/app_dev.php/css/eb2d30c_part_1_jqueryMenus_1.css" rel="stylesheet">
and when I open it, it is not css but html because there is an error :
<h1>Exception thrown when handling an exception (Symfony\Component\HttpKernel\Exception\FlattenException: Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in C:\wamp\www\viewkit\vendor\monolog\monolog\src\Monolog\Formatter\NormalizerFormatter.php line 99)</h1>
<div class="block_exception clear_fix">
<h2><span>1/1</span> <abbr title="ErrorException">ErrorException</abbr>: Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in C:\wamp\www\viewkit\vendor\monolog\monolog\src\Monolog\Formatter\NormalizerFormatter.php line 99</h2>
</div>
<div class="block">
<ol class="traces list_exception">
<li> in C:\wamp\www\viewkit\vendor\monolog\monolog\src\Monolog\Formatter\NormalizerFormatter.php line 99</li>
any idea where it could come from ?
Put the cssembed-0.4.5.jar in app/Resources/java directory as you specified in the configuration.
Related
I am following the django-cms documentation and so far I only have one template home.html:
{% load cms_tags sekizai_tags %}
<html>
<head>
<title>{% page_attribute "page_title" %}</title>
{% render_block "css" %}
</head>
<body>
{% cms_toolbar %}
{% placeholder "content" %}
{% render_block "js" %}
</body>
</html>
And my url.py looks like this:
from django.contrib import admin
from django.urls import path, re_path, include
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^', include('cms.urls')),
]
I can login and create a page, but when I logout and navigate to `localhost:8000' I get:
AttributeError at /
'TemplateResponse' object has no attribute '_headers'
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 3.2
Exception Type: AttributeError
Exception Value:
'TemplateResponse' object has no attribute '_headers'
Exception Location: /usr/local/lib/python3.9/site-packages/cms/cache/page.py, line 84, in set_page_cache
Python Executable: /usr/local/bin/python
Python Version: 3.9.4
Python Path:
['/app/app',
'/usr/local/lib/python39.zip',
'/usr/local/lib/python3.9',
'/usr/local/lib/python3.9/lib-dynload',
'/usr/local/lib/python3.9/site-packages']
I am not sure if I did something wrong here. I would like to see how the webpage looks like for someone who does not have an account and cannot login.
Support for django 3.2 has been introduced in django-cms 3.9 so upgrade to this version to resolve this error.
I've tried to add webpack to a Symfony 3.1 app. The problem is, when I add HMR, the asset function doesn't resolve correctly
// base.html.twig
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
// app/config/config_dev.yml
framework:
assets:
base_path: "http://localhost:8080"
Result: <script src="/http://localhost:8080/bundles/fosjsrouting/js/router.js"></script>
How can I tell Symfony to not prepend the starting / if the base_path begins with http://?
You can use base_urls. Protocol/host/port should not be used in base_path for assets.
https://symfony.com/doc/current/reference/configuration/framework.html#assets
I'm working on a symfony 2.8 project.
Assetic is used to combine CSS to one file. I have written my own CSS as SCSS an use compass to compile it.
I now added a 3. party lightbox plugin and can't get assetic to put my SCSS and the plain CSS of the lightbox together.
Assetic config:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
filters:
cssrewrite: ~
compass:
bin: /usr/local/bin/compass
apply_to: '\.scss$'
HTML-Head:
{% stylesheets
'css/screen.scss'
'assets/vendor/lightgallery/dist/css/lightgallery.css'
filter='cssrewrite,compass' output='css/compiled/app.css' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
With this I get an error like:
/*
[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
[message] An error occurred while running:
'/usr/local/bin/ruby' '/usr/local/bin/compass' 'compile' '/Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev' '--boring' '--images-dir' '/Applications/XAMPP/xamppfiles/htdocs/XYZ/app/../web/images' '--config' '/Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev/assetic_compass05Ld1V' '--sass-dir' '' '--css-dir' '' '/Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev/assetic_compassRm5H7y.css'
Error Output:
WARNING on line 2 of /Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev/assetic_compassRm5H7y.css:
This selector doesn't have any properties and will not be rendered.
WARNING on line 3 of /Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev/assetic_compassRm5H7y.css:
This selector doesn't have any properties and will not be rendered.
Output:
error /Applications/XAMPP/xamppfiles/htdocs/XYZ/app/cache/dev/assetic_compassRm5H7y.css (Line 5: Invalid CSS after "'lg'": expected expression (e.g. 1px, bold), was ";")
Compilation failed in 1 files.
Input:
/*! lightgallery - v1.2.21 - 2016-06-28
* http://sachinchoolur.github.io/lightGallery/
* Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
#font-face {
font-family: 'lg';
src: url("../fonts/lg.eot?n1z373");
src: url("../fonts/lg.eot?#iefixn1z373") format("embedded-opentype"), url("../fonts/lg.woff?n1z373") format("woff"), url("../fonts/lg.ttf?n1z373") format("truetype"), url("../fonts/lg.svg?n1z373#lg") format("svg");
font-weight: normal;
font-style: normal;
}
[...]
If I just rename the CSS file to SCSS it works. I don't know why compass has a problem processing the file when I send it as CSS to assetic.
Besindes this behaviour assetic shouldn't send the CSS file to compass anyway.
What did I do wrong?
Here's my config.yml file
framework:
#code
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
packages:
blade:
base_path: '/bundle/bladecms'
#code
I'd like to set base_path for blade prefix to be able to use
<img src="{{ asset('images/image.png', 'blade') }}"/>
instead
<img src="{{ asset('bundle/bladecms/images/image.png') }}"/>
So what's a problem? When I use 'base_path' I get
Unrecognized option "base_path" under "framework.templating.packages.blade"
If I change base_path to base_url I get
"/bundle/bladecms" is not a valid URL
How to configure it properly?
You have to set a valid URL (e.g. http://yourhost/bundle/bladecms) .
Make your configuration like this :
framework:
templating:
packages:
blade:
assets_base_urls: '%router.request_context.scheme%://%router.request_context.host%/bundle/bladecms
And use it like follows :
<img src="{{ asset('images/image.png', 'blade') }}"/>
The first parameter router.request_context.scheme is the protocol used by the request (i.e. http, ssl).
The second router.request_context.host is the host of the request.
Like this, your base_url change dynamically depending on the request.
See http://symfony.com/doc/current/reference/configuration/framework.html#assets-base-urls
Using Symfony and Assetic I cannot get css images to 'dump' correctly in my prod environment.
They continue to link back to the web/bundle/...etc.. location.
I have a very basic cssrewrite setup:
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
filters:
cssrewrite:
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
My template:
{% stylesheets 'bundles/<my bundle>/css/style.css' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
I have the prod version of app.php in place with debug false:
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$apcLoader = new ApcClassLoader('sf2', $loader);
$loader->unregister();
$apcLoader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I have done:
app/console assets:install --symlink
All seems fine
Then I clear the prod cache
OK
app/console assetic:dump --env=prod
My css and js copy out with the expected file names, however I still have url('../../bundle/..etc../images/bg.png'); appearing in my css
In the symlinked version the css is: url('../images/bg.png');
So it must be something to do with assetic.
What I expect is for the 'dump'ed css to contain links like url('../images/bg.png');
And for the images themselves to be copied out to web/images/123abc.png
Should I expect this from assetic and if so what am I doing wrong?
Thanks, in advance.
// In Config.yml file
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
In app.php file
//If it is in dev environment In your app_dev.php file contain like this
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
// If it is in prod environment, In your app.php file contain like this
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();