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 %}
<a href="{{ portal.profile_url }}">Edit profile</a></span>
<a href="{{ portal.logout_url }}">Signout</a>
{% else %}
<a href="{{ portal.login_url }}">Login</a>
<a href="{{ portal.signup_url }}">Signup</a></span>
{% 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’ %}
<!-- Style for announcements forum -->
{% when ‘ideas’ %}
<!-- Style for Idea forums -->
{% when ‘questions’ %}
<!-- Style for questions forum -->
{% when ‘problems’ %}
<!-- Style for problems forum -->
{% else %}
<!-- Default forum style -->
{% endcase %}
Switch cases come in handy especially when you want to provide a different style based on the solution category or forum topic type.