filter boolean variable in a twig template

symfony, twig

Solution

Quick way to achieve that is to use the ternary operator:

{{ bool_var ? 'Yes':'No' }}

http://twig.sensiolabs.org/doc/templates.html#other-operators

You could also create a custom filter that would do this. Read about custom TWIG extensions - http://symfony.com/doc/current/cookbook/templating/twig_extension.html

Problem

I have a boolean variable(0, 1) in my database and I want to filter it to a word 0 for 'NO', and 1 for 'Yes'. how can I do that in a twig template I want something like `{{ bool_var | '??' }}` where the '??' is the filter

Original source

Related problems