twig文件支持html吗,如何在Symfony2 / Twig模板中包含原始HTML文件?

简要介绍twig文件扩展名(取自文档):

Every template name also has two extensions that specify the format and engine for that template.

AcmeBlogBundle:Blog:index.html.twig - HTML format, Twig engine

AcmeBlogBundle:Blog:index.html.php - HTML format, PHP engine

AcmeBlogBundle:Blog:index.css.twig - CSS format, Twig engine

By default, any Symfony2 template can be written in either Twig or PHP, and the last part of the extension (e.g. .twig or .php) specifies which of these two engines should be used. The first part of the extension, (e.g. .html, .css, etc) is the final format that the template will generate.

因此,对于包含.html文件的文件,即使没有引发错误,也是至关重要的.

所以你有3个选择:

>如果文件是纯粹的JavaScript,那么将它们作为脚本标签包含在您的页面中.

>如果它们是混合的HTML和JS,然后用{%raw%}转义JS,并将这些文件包含为foo.html.twig模板.如果这样包含许多脚本,那么很可能您的设计人员可以通过一些重构将其大部分脚本移动到外部文件(参见选项1)

>如果你真的坚持你可以总是写一个Twig扩展名来包含原始的HTML文件. (编辑:请参阅@ Haprog的下面的答案有关此选项的更多详细信息).

{{include_html(‘foo / bar.html’)}}

> UPDATE 2015 twig已经添加了源代码功能:

{{source(‘AcmeSomeBundle:Default:somefile.html.twig’)}}

在下面的选项4的评论中,向@Nigel Angel致敬.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值