PHP Classes

File: libs/Twig/doc/filters/default.rst

Recommend this page to a friend!
  Classes of william amed   Raptor 2   libs/Twig/doc/filters/default.rst   Download  
File: libs/Twig/doc/filters/default.rst
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Raptor 2
Framework that takes routes from annotations
Author: By
Last change:
Date: 8 years ago
Size: 858 bytes
 

Contents

Class file image Download
``default`` =========== The ``default`` filter returns the passed default value if the value is undefined or empty, otherwise the value of the variable: .. code-block:: jinja {{ var|default('var is not defined') }} {{ var.foo|default('foo item on var is not defined') }} {{ var['foo']|default('foo item on var is not defined') }} {{ ''|default('passed var is empty') }} When using the ``default`` filter on an expression that uses variables in some method calls, be sure to use the ``default`` filter whenever a variable can be undefined: .. code-block:: jinja {{ var.method(foo|default('foo'))|default('foo') }} .. note:: Read the documentation for the :doc:`defined<../tests/defined>` and :doc:`empty<../tests/empty>` tests to learn more about their semantics. Arguments --------- * ``default``: The default value