i. If/Else

The If-Else-Unless structure from the Liquid library allows you to branch HTML statements just like you would with a traditional programming language. It’s easy to implement and takes just a few steps.
The example below shows how you can create an If-Else structure to show different links to logged in and logged out users in the portal.

{% if portal.user %}


Edit profile

Signout


{% else %}


Login

Signup


{% endif %}


ii. Cases:
Liquid Cases are similar to switch cases used in popular programming languages. It checks a single expression with multiple values and branches with different statements correspondingly.

{% case forum.type_name %}

{% when ‘announcement’ %}

 


{% when ‘ideas’ %}

 


{% when ‘questions’ %}

 


{% when ‘problems’ %}

 


{% else %}

 


{% endcase %}


Switch cases come in handy especially when you want to provide a different style based on the solution category or forum topic type.


Next: Looping and Iteration