Last updated: 2017-06-12

Source: https://support.freshdesk.com/support/solutions/articles/65037-conditional-statements

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.

Next: Looping and Iteration