[英]include symfony base assets that aren't in a bundle
我正在尝试使用Assetic来包含不在捆绑包中的基本CSS和JS资产。 它们位于MySymfonyApp/app/Resources/public/css/
和MySymfonyApp/app/Resources/public/js/
。
我的base.html.twig
模板中包含以下内容,但出现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 %}
我也尝试了以下相同的结果。
{% stylesheets '../app/Resources/public/css/*' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
如何引用非捆绑资产?
解:
app/Resources/public/*
中的资产是特例。 它们可以轻松地进行管理。
如果您调用控制台命令,这些将全部复制(或符号链接)到web/public/*
:
app/console assets:install web
... 要么 ...
app/console assets:install web --symlink
现在,可以直接从web
夹中包含资产。
<script src="{{ asset('js/jquery.js') }}"></script>
小费:
如果您需要从相对于kernel-rootdir的其他目录中获取资产。
您可以执行以下操作:
# 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
现在执行控制台命令...
app/console assetic:dump
...并将它们包括在您的模板之一中:
{% stylesheets '@css_boostrap' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.