php - Compare Value to String IF/FOR Statement -
i'm trying compare value of each saved entity , organize results sections. can't life of me find how compare variable string using twig. i've tried error's except following code instead of failing, skips if's , shows else. i'm assuming i've got wrong twig documentation has no mention of how (i think) , i'm beginning think i'm going wrong way. maybe should doing in controller?
{% product in entity.product %}     {% if product.dish.dishcat == 'starter' %}          <h3>starter</h3>         <p>{{ product.dish }}</p>     {% elseif product.dish.dishcat == 'main'%}         <h3>main</h3>         <p>{{ product.dish }}</p>     {% elseif product.dish.dishcat == 'desert'%}         <h3>desert</h3>         <p>{{ product.dish }}</p>     {% else %} // get's here.         <p> fail!</p>         <p>{{product.dish.dishcat}} {{product.dish.id}}</p> //i print 'product.dish.dishcat' ensure it's got value does...     {% endif %} {% endfor %} result =
fail! mains 2
fail! starters 0
fail! starters 1
fail! deserts 3
fail! mains 4
any suggestion's welcome.
the results end 's' while conditional statements not. try:
{% product in entity.product %}     {% if product.dish.dishcat == 'starters' %}          <h3>starter</h3>         <p>{{ product.dish }}</p>     {% elseif product.dish.dishcat == 'mains'%}         <h3>main</h3>        <p>{{ product.dish }}</p>     {% elseif product.dish.dishcat == 'deserts'%}         <h3>desert</h3>         <p>{{ product.dish }}</p>     {% else %} // get's here.         <p> fail!</p>         <p>{{product.dish.dishcat}} {{product.dish.id}}</p>         //i print 'product.dish.dishcat' ensure it's got value does...    {% endif %} {% endfor % i think should try fix variables , not let of them end 's'.
Comments
Post a Comment