Twig

灵活、快速且安全的
PHP 模板引擎

a Symfony Product
文档 标签 deprecated
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题与反馈

许可

Twig documentation 在新的 BSD license 下获得许可。

已弃用

当在模板中使用 deprecated 标签时,Twig 会生成弃用通知(通过调用 trigger_error() PHP 函数)

1
2
3
{# base.html.twig #}
{% deprecated 'The "base.html.twig" template is deprecated, use "layout.html.twig" instead.' %}
{% extends 'layout.html.twig' %}

您还可以通过以下方式弃用宏

1
2
3
4
5
{% macro welcome(name) %}
    {% deprecated 'The "welcome" macro is deprecated, use "hello" instead.' %}

    ...
{% endmacro %}

请注意,默认情况下,弃用通知是静默的,既不显示也不记录。请参阅 Recipes 了解如何处理它们。

3.11

packageversion 选项在 Twig 3.11 中添加。

您可以选择添加引入弃用的 package 和 version

1
2
{% deprecated 'The "base.html.twig" template is deprecated, use "layout.html.twig" instead.' package='twig/twig' %}
{% deprecated 'The "base.html.twig" template is deprecated, use "layout.html.twig" instead.' package='twig/twig' version='3.11' %}

注意

不要使用 deprecated 标签来弃用 block,因为弃用可能无法始终正确触发。