我最近开始使用Symfony,我的资产出现了一些问题。我使用Assetic,将我的资产放在Resources/public中,并在bundle/techdemo中进行链接。
在我的twig模板中,我有以下部分:
{% block stylesheets %}
{% stylesheets 'bundles/techdemo/css/*' filter='cssrewrite'%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
{% javascripts 'bundles/techdemo/js/*' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}将我所有的.css和.js文件放入HTML-head。
这有点用..在我的浏览器源代码中,我得到了如下内容:
<link rel="stylesheet" href="/css/ae8ddf1_part_1_style_8.css" />
<link rel="stylesheet" href="/css/ae8ddf1_part_1_tags_9.css" />
<link rel="stylesheet" href="/css/ae8ddf1_part_1_typeahead.tagging_10.css" />
<script src="/js/c81691d_part_1_bootstrap.min_1.js"></script>
<script src="/js/c81691d_part_1_initial.min_2.js"></script>
<script src="/js/c81691d_part_1_jquery-price-slider_3.js"></script>
<script src="/js/c81691d_part_1_jquery.barrating.min_4.js"></script> 但路径是错误的。我在localhost:8000/app_dev.php/下访问该项目,因此文件被链接到例如localhost:8000/app_dev.php/js/c81691d_part_1_bootstrap.min_1.js,它抛出一个未定义路由的expeption。
这是我的Assetic配置:
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ TechDemoBundle]
filters:
cssrewrite: ~我已经阅读了很多资料,但还没有找到解决方案。我使用的是最新的2.8版本。
编辑:
对一个文件使用显式路径可以很好地工作:
<link rel="stylesheet" href="{{ asset('bundles/techdemo/css/style.css') }}" />源代码中的链接是这样的:localhost:8000/bundles/techdemo/css/style.css
如何更改多个资产的目录?
发布于 2017-07-02 20:03:58
尝试更改app/config/config.yml:
framework:
templating:
engines: ['twig']
assets_base_urls:
http: [http://yourhost.com]https://stackoverflow.com/questions/44869712
复制相似问题