M
M
magary42017-02-20 16:53:13
symfony
magary4, 2017-02-20 16:53:13

How to suppress an exception in twig?

when in the template, when accessing the property, it turns out that it is undefined, an exception is thrown. first I made an error page. but now I want to just ignore in certain cases.
after all, the page as a whole is alive
so that if the exception in the template simply does not show anything, but the template continued to draw
, I can’t find how to do it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shagguboy, 2017-02-20
@magary4

{% if foo.bar is defined %}
    ...
{% endif %}

{{ var.foo|default('foo item on var is not defined') }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question