mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 18:06:46 +00:00
Added code snippet to documentation to describe handling null values with date filter
This commit is contained in:
@@ -56,3 +56,10 @@ The default timezone can also be set globally by calling ``setTimezone()``:
|
||||
.. _`date`: http://www.php.net/date
|
||||
.. _`DateTime`: http://www.php.net/DateTime
|
||||
.. _`DateInterval`: http://www.php.net/DateInterval
|
||||
|
||||
If the value passed to the ``date`` filter is null, it will return the current date by default.
|
||||
If an empty string is desired instead of the current date, use a ternary operator:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }}
|
||||
|
||||
Reference in New Issue
Block a user