Twig

The flexible, fast, and secure
template engine for PHP

a Symfony Product
Docs Tags deprecated
You are reading the documentation for Twig 3.x. Switch to the documentation for Twig 1.x, 2.x.

Questions & Feedback

License

Twig documentation is licensed under the new BSD license.

deprecated

Twig generates a deprecation notice (via a call to the trigger_error() PHP function) where the deprecated tag is used in a template:

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

You can also deprecate a macro in the following way:

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

    ...
{% endmacro %}

Note that by default, the deprecation notices are silenced and never displayed nor logged. See Recipes to learn how to handle them.

3.11

The package and version options were added in Twig 3.11.

You can optionally add the package and the version that introduced the deprecation:

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

Note

Don't use the deprecated tag to deprecate a block as the deprecation cannot always be triggered correctly.