I'm trying to use Assetic to include my base css and js assets that aren't in a bundle. They're located in MySymfonyApp/app/Resources/public/css/
and MySymfonyApp/app/Resources/public/js/
.
I have the following in my base.html.twig
template but i'm getting 404s
{% stylesheets '%kernel.root_dir%/Resources/public/css/*' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
{% javascripts
'%kernel.root_dir%/Resources/public/js/jQuery.js'
'%kernel.root_dir%/Resources/public/js/*' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
I've also tried the following with the same result.
{% stylesheets '../app/Resources/public/css/*' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
How do i reference assets that aren't in bundles?
solution:
assets in app/Resources/public/*
are a special case. They can easily be managed.
These will all be copied (or symlinked) to web/public/*
if you invoke the console command:
app/console assets:install web
... or ...
app/console assets:install web --symlink
Now the assets can be included from the web
-folder directly.
<script src="{{ asset('js/jquery.js') }}"></script>
tip:
If you need to fetch assets from other directories relative to the kernel-rootdir.
You can do something like this:
# app/config/config.yml
assetic:
assets:
css_boostrap:
inputs:
- %kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.min.css
- %kernel.root_dir%/../vendor/myself/bootstrap-theme/*.css
js_jquery:
inputs:
- %kernel.root_dir%/Resources/public/js/jquery.min.js
Now execute the console command ...
app/console assetic:dump
... and include them in one of your templates:
{% stylesheets '@css_boostrap' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.