-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Assetic fixes #1991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assetic fixes #1991
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,21 @@ drawn from various sources such as from within a bundle: | |
<link rel="stylesheet" href="<?php echo $view->escape($url) ?>" /> | ||
<?php endforeach; ?> | ||
|
||
.. tip:: | ||
|
||
For the above example to work, you must also add your bundle to the list | ||
of bundles that Assetic handles, which is empty by default: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
assetic: | ||
debug: "%kernel.debug%" | ||
use_controller: false | ||
bundles: [ AcmeFooBundle ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
filters: | ||
# ... | ||
|
||
In this example, all of the files in the ``Resources/public/js/`` directory | ||
of the ``AcmeFooBundle`` will be loaded and served from a different location. | ||
The actual rendered tag might simply look like: | ||
|
@@ -87,10 +102,42 @@ The actual rendered tag might simply look like: | |
.. note:: | ||
|
||
This is a key point: once you let Assetic handle your assets, the files are | ||
served from a different location. This *can* cause problems with CSS files | ||
served from a different location. This *will* cause problems with CSS files | ||
that reference images by their relative path. However, this can be fixed | ||
by using the ``cssrewrite`` filter, which updates paths in CSS files | ||
to reflect their new location. | ||
|
||
Unfortunately, the ``cssrewrite`` filter does not work when using the | ||
``@AcmeFooBundle`` syntax to reference the assets. This is a known | ||
limitation. A workaround is to use the ``output`` option to change the | ||
location the files are served from to a path from which the relative paths | ||
work, e.g.: | ||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: html+jinja | ||
|
||
{% stylesheets | ||
output='bundles/acmefoo/css/compiled.css' | ||
'@AcmeFooBundle/Resources/public/css/*' | ||
%} | ||
<link rel="stylesheet" href="{{ asset_url }}" /> | ||
{% endstylesheets %} | ||
|
||
.. code-block:: html+php | ||
|
||
<?php foreach ($view['assetic']->stylesheets( | ||
array('@AcmeFooBundle/Resources/public/css/*'), | ||
array(), | ||
array('output' => 'bundles/acmefoo/css/compiled.css') | ||
) as $url): ?> | ||
<link rel="stylesheet" href="<?php echo $view->escape($url) ?>" /> | ||
<?php endforeach; ?> | ||
|
||
Of course, this assumes that all the CSS files you serve in this block use | ||
relative paths that start from the same location, which is not always | ||
convenient. This is the reason this is called a *workaround* and not a | ||
*solution*. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually didn't know that you could work around this problem by changing the output to a path in the bundle. It's interesting, but I think that we should just tell people to not use the So, can you rebase against the latest changes, then simple mention the problem with using the Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, I’ll do that. |
||
|
||
Combining Assets | ||
~~~~~~~~~~~~~~~~ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%kernel.debug%
is the default value for theassetic.debug
setting, so I think this line isn't needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in the config like this in the standard distribution though so its in keeping with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small detail either way, but what I'd love the most is to use the
# ...
in this spot:Also, is this new note actually correct yet? My impression is that you don't need to add your bundle to the
bundles
configuration until you place astylesheets
orjavascripts
tag into a template that lives inside that bundle. If yourstylesheets
orjavascripts
tags are only in a template inapp/Resources/views
(even if you're referencing CSS/JS files that are in some bundle), then you don't need to add the bundle to thebundles
key.If I'm wrong, some please shout at me! :) I just wanted to make sure we were clear on that before merging.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suspect that you are correct. It makes a lot more sense to me now. I’ll make some tests next week and rewrite accordingly.