Exception handling inside twig template

Dr Magneto picture Dr Magneto · Sep 7, 2015 · Viewed 7.5k times · Source

i am new to symfony2. my project has two entity

    [1] Category and
    [2] Evaluation

and category has many evaluation, so the problem is when i delete the category and then display the evaluation then it display me error like

"An exception has been thrown during the rendering of a template ("Entity was not found.") in HfAppBundle:SpecificEvaluations:index.html.twig at line 137. ".

on line number 137 this is the content {{evaluation.category.name}}. i had also try with

    {% if evaluation.category.name is not null %}
        {{evaluation.category.name}}
    {% endif %}

but it also give me same error. any one can help ?

thanks

Answer

malcolm picture malcolm · Sep 7, 2015

Use twig test defined :

{% if evaluation.category.name is defined %}
    {{evaluation.category.name}}
{% endif %}