Twig embed vs include, any reason to use include(树枝嵌入与包含,任何使用包含的理由)
问题描述
为什么不总是使用嵌入?
Why not just always use embed?
根据文档,嵌入标签结合了包含和扩展标签的行为.
According to the docs the embed tag combines the behavior of the include and extend tags.
我知道,在很多情况下,您不需要进行扩展,而只想渲染另一个模板的内容,但在我看来,您总是可以使用 embed 来实现该目的.嵌入是否有任何性能影响需要注意?我缺少任何功能差异吗?
I understand that in a lot of cases you don't need to do extend and only want to render the contents of another template, but it seems to me like you could just always use embed and serve that purpose. Are there any performance ramifications of embed to be aware of? Any functionality differences I'm missing?
推荐答案
总结一下Embed 和 Include 如下,
I would summarize the differences and similarities between Embed and Include as follow,
- 两者都被添加到 twig 以使 HTML 代码片段可重复使用.
- 两者都用于模板的功能分离(页脚、页眉、...)
- 两者都是动态的.
- Include 用于包装 HTML 结构不灵活的代码.
- 嵌入 具有灵活性.
- Both were added to twig to make HTML code snippets reusable.
- Both are used for functional separation of templates (footer, header, ...)
- Both are dynamic.
- Include is used to wrap code that has non flexible HTML structure.
- Embed allows flexibility.
基于差异,Include 应仅使用 当您需要将模板拆分为许多功能子模板并在其他地方重用包装的代码时.
Based on the differences, Include should be used only when you need to split a template into many functional sub-templates and reuse the wrapped code elsewhere.
而 Embed 在您需要自定义可重用模板时使用.
While Embed is used when you need to customise the reusable templates.
所以,它更多的是设计问题(性能、代码执行……)
So, it's more a matter of design than anything else (performance, code execution, ...)
选择适合您需要的助手.
Choose the helper that fit your needs.
这篇关于树枝嵌入与包含,任何使用包含的理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:树枝嵌入与包含,任何使用包含的理由
- Mod使用GET变量将子域重写为PHP 2021-01-01
- Laravel 仓库 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01