IF/ELSE

FLEX handles conditionals using IF / ELSE statements

All IF statements start with the word 'if':

{% if attr_top_recipe == 'Yes' %}
<!-- or -->
{% if $x == 2 %}

It is recommended if you are using a drop down attribute that you use the value of the attribute and not the output value by using "_value". For more information, read the section on Attributes.

All IF statements must end with an 'endif':

{% if attr_top_recipe == 'Yes' %}
<h1>Top Recipe</h1>
{% endif %}
<!-- or -->
{% if $x == 2 %}
<h1>Yes, we found number 2</h1>
{% endif %}

Any content within the if and endif statement will either be rendered or output to the users screen.

If you want to execute a different part of the code if the if condition is not met, you can use 'else' or 'elseif'.

Example:

{% if attr_top_recipe == 'Yes' %}
<h1>Top Recipe</h1>
{% elseif attr_top_recipe == 'recommended' %}
<h1>Recommended Recipe</h1>
{% else %}
<h1>Basic Recipe</h1>
{% endif %}

NOTE: IF/ELSE statements work well within loops and with define and increment and even attributes


Start your free, no-risk trial today.