Reputation: 4650
I have a field in the database which is with nullable=true, but when I set a null value to it and then display it in twig this way {{ null_variable}} it displays the text "empty_value". How can I display nothing instead of this text? The onlu thing I can think of is this way
{% if variable==NULL %}
<td></td>
but I don't think it's a good way of doing this.
Upvotes: 0
Views: 514
Reputation: 47585
That's a weird behavior, Twig shouldn't returns 'empty_value'.
Are you sure you are not using it within a form?
Anyway, here is someway to do:
{% if variable is defined %} // $variable was never defined
{% if variable is empty %} // $variable is defined but empty (null, empty string, 0)
you may also use the default
filter:
{% variable|default('') %}
Upvotes: 2