Twig and empty date

Ran in to a small problem when I was programming today. I had an Entity Person that had a birthday that could be empty (if we did not know it). When it was displayed with twig an empty value was displayed with the current date.

So to display an empty date with twig you have to do something like this:

{% if entity.birthday %}
    {{ entity.birthday|date('Y-m-d') }}
{% else %}
    No Value
{% endif %}

May the force be with you!

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>