[英]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.