lets say i have some data like this :
answers: [
{
answerText: "please",
small: false
},
{
answerText: "help",
small: true
},
{
answerText: "me",
small: false
}
],
and i want to set a boolean that´s true if there is an answer where small is true. and i need to use it outside the loop i´m iterating over answers.
im trying arround and just dont get it, i think my nearest attempt is sth. like this
{% set zyx = if 'small' in question['answers'] %}
{% set zyx = 'small' in question['answers'] %}
{% set zyx = 'small:true' in question['answers'] %}
{% set zyx = true in question['answers'] %}
but they all dont work as i expect
for any help thanks in advance
You cannot use statements in an expression. Removing if
will do the trick:
{% set zyx = 'small' in question['answers'] %}
EDIT
To check if answer.small
is true
, use:
{% set zyx = question['answers']['small'] is true %}
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