I'd like to display checked if a variable is null so I have make this code
{{ form_widget(form.showPrice, {% if travel is null %} {'attr': {'checked': 'checked'}} {% endif %} ) }}
but I got this error
A hash key must be a quoted string, a number, a name, or an expression enclosed in
parentheses (unexpected token "operator" of value "%" in AppBundle:Dashboard/Travel:form.html.twig at line 100
Delimiters like {% ... %}
is used to execute statements such as for-loops.
Delimiters like {{ ... }}
prints the result of an expression to the template.
You messed up with them. The right code would be:
{{ form_widget(form.showPrice, (travel is null ? {'attr': {'checked': 'checked'} }) ) }}
Try this :
{{ form_widget(form.showPrice, (travel is null ? {'attr': {'checked': 'checked'} } : {}) ) }}
you need to also pass the false option - in this case {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With