Oli*_*ons 11 resourcebundle symfony assetic
我有我的自定义资源目录,我的包有一些文件:
/longpathtoSymfony/src/MyOwn/Bundle/MyOwnBundle/Resources/public
|-- bootstrap
| |-- css
| | |-- bootstrap-theme.css
| | |-- bootstrap-theme.min.css
| | |-- bootstrap.css
| | |-- bootstrap.min.css
| | `-- carousel.css
| |-- fonts
| | |-- glyphicons-halflings-regular.eot
| | |-- glyphicons-halflings-regular.svg
| | |-- glyphicons-halflings-regular.ttf
| | `-- glyphicons-halflings-regular.woff
| `-- js
| |-- bootstrap.js
| |-- bootstrap.min.js
| |-- holder.js
| `-- respond.min.js
|-- css
| `-- custom.css
|-- fonts
| |-- glyphicons-halflings-regular.svg
| |-- glyphicons-halflings-regular.ttf
| `-- glyphicons-halflings-regular.woff
|-- images
|-- img
`-- js
|-- html5shiv.js
|-- jquery-1.10.2.min.map
|-- jquery.js
`-- less-1.3.3.min.js
Run Code Online (Sandbox Code Playgroud)
并且所有js和css文件都正确放入公用文件夹,因此我可以访问bootstrap/css/xxx.css文件等,但字体文件除外.
我不知道应该怎么做才能将它们复制到web目录中.如果我尝试,php app/console assetic:dump那么只复制css和js文件:
php app/console assetic:dump
Dumping all dev assets.
Debug mode is on.
18:41:17 [file+] /longpathToSymfony/app/../web/css/bef717e.css
18:41:17 [file+] /longpathToSymfony/app/../web/css/bef717e_bootstrap.min_1.css
18:41:17 [file+] /longpathToSymfony/app/../web/js/6f9045a.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/6f9045a_html5shiv_1.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/6f9045a_respond.min_2.js
18:41:17 [file+] /longpathToSymfony/app/../web/css/0c1e28e.css
18:41:17 [file+] /longpathToSymfony/app/../web/css/0c1e28e_carousel_1.css
18:41:17 [file+] /longpathToSymfony/app/../web/js/0aa0509.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/0aa0509_jquery_1.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/0aa0509_bootstrap.min_2.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/0aa0509_holder_3.js
18:41:17 [file+] /longpathToSymfony/app/../web/js/0aa0509_less-1.3.3.min_4.js
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能包含字体文件?我遇到了同样的问题jquery-1.10.2.min.map,它是动态下载的.有没有办法对symfony说"嘿把它放在网络资源文件夹中,因为我的一些组件需要它"?
Cow*_*lby 18
我有同样的问题,我只是尝试使用以下作为解决方法.到目前为止似乎工作.
{% stylesheets
output='assets/fonts/glyphicons-halflings-regular.ttf'
'bundles/bootstrap/fonts/glyphicons-halflings-regular.ttf'
%}{% endstylesheets %}
Run Code Online (Sandbox Code Playgroud)
请注意省略任何输出,这意味着模板上没有显示任何内容.当我运行assetic:dump文件被复制到所需的位置,并且css包括按预期工作.
在树枝上你应该有一个javascripts块与这样的东西:
{% block javascripts %}
{% javascripts
'bundles/myown/bootstrap/js/bootstrap.js'
'bundles/myown/bootstrap/js/respond.js'
'bundles/myown/js/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
同样适用于你的CSS.
{% block stylesheets %}
{% stylesheets
'bundles/myown/bootstrap/css/bootstrap-theme.css'
'bundles/myown/css/*'
filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用以下命令安装这些资产以便于开发(app_dev.php):
php app/console cache:clear --env=dev
php app/console assets:install web --symlink
Run Code Online (Sandbox Code Playgroud)
此时,您应该在/ longpathtoSymfony/web/bundles/myown中看到链接回捆绑资源的符号链接文件夹.符号链接选项的好处是您可以更改bundle文件夹中的脚本,而不必运行assets:install命令来查看浏览器中的这些更改.刷新吧.
准备好转移到生产时,请使用assetic:dump命令.这只适用于css,js和图像.因此,您需要手动将fonts文件夹移动到Web目录中,或者编写自己的脚本来为您移动这些内容.
确保让Assetic在config.yml中了解您的包
assetic:
bundles: [ 'MyOwnBundle' ]
Run Code Online (Sandbox Code Playgroud)
现在您可以使用以下方式转储生产就绪资产:
php app/console cache:clear --env=prod
php app/console assetic:dump --env=prod
Run Code Online (Sandbox Code Playgroud)
因此,当您在浏览器中查看它时,只需删除app_dev.php,它应该从单个文件中加载您的css和javascript,这些文件被转储到web/css和web/js文件夹中.这只是使用这些工具的一种方法,但在大多数情况下它似乎对我有用.
| 归档时间: |
|
| 查看次数: |
15833 次 |
| 最近记录: |