使用 AsseticBundle 包含 Twig 视图中的资源
在 Symfony 1.4 中,我通常仅包含所需的资源:
apps/myApp/config/view.yml (每个页面中使用的常规资源)
stylesheets: [main.css]
javascripts: [lib/jquery.js, lib/jquery.qtip.js, backend/main.js]
apps/myApp/modules/someModule/ templates/someTemplateSuccess.php (仅用于此视图、部分等的资产)
<?php use_stylesheet('backend/datagrid.css') ?>
<?php use_javascript('backend/datagrid.js') ?>
,然后最终在 apps/myApp/templates/layout.php 中链接这些内容:
<?php include_stylesheets() ?>
<?php include_javascripts() ?>
那么,如何在 Twig 视图中使用 AsseticBundle 来做到这一点呢?
我真的很困惑...谢谢!
In Symfony 1.4 I use to include just the needed assets with:
apps/myApp/config/view.yml (general assets to be used in every page)
stylesheets: [main.css]
javascripts: [lib/jquery.js, lib/jquery.qtip.js, backend/main.js]
apps/myApp/modules/someModule/templates/someTemplateSuccess.php (assets just for this view, partial, etc)
<?php use_stylesheet('backend/datagrid.css') ?>
<?php use_javascript('backend/datagrid.js') ?>
and then finally linking those in apps/myApp/templates/layout.php:
<?php include_stylesheets() ?>
<?php include_javascripts() ?>
So, how to do this using the AsseticBundle in Twig views?
I'm really confused... thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我到了这里:
https://github.com/kriswallsmith/symfony-sandbox/commit /f1fc1d0cf2fe69660f94f33719a4508d6e9e25ae
,它有效!
它像这样:
src/MySite/MyBundle/Resources/css/datagrid.css
将其包含在视图中:
< strong>src/MySite/MyBundle/Resources/views/MyViews/myview.html.twig
最后,让我们打印它:
app/Resources/views/base.html.twig
太棒了!
更新:
我仍然不知道为什么,但是:
只能将 debug 设置为 false,因此最好的方法是配置它:
app/config/config.yml
Ok, I got here:
https://github.com/kriswallsmith/symfony-sandbox/commit/f1fc1d0cf2fe69660f94f33719a4508d6e9e25ae
and it WORKS!
it goes like this:
src/MySite/MyBundle/Resources/css/datagrid.css
to include it in the view:
src/MySite/MyBundle/Resources/views/MyViews/myview.html.twig
and finally, lets print it:
app/Resources/views/base.html.twig
Great!
UPDATE:
I still don't know why but:
Only works setting debug to false, so the best way to do this is configuring it:
app/config/config.yml