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.
这篇关于树枝嵌入与包含,任何使用包含的理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:树枝嵌入与包含,任何使用包含的理由
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01