if, elsif, and else Tags

Only execute code if a certain condition is met.

Description

if executes a block of code only if a certain condition is met.

      {% assign day_of_week = now | date: '%A' %}
      
      {% if day_of_week == 'Monday' %}
        <p class="building-on-fire">
          Looks like somone has a case of the Mondays!
        </p>
      {% endif %}
      

elsif and else add more conditions within an if or unless block.

      <h1>
        {% if current_page.home? %}
          Welcome Home
        {% elsif current_page.title == 'Dear Diary' %}
          Private
        {% else %}
          {{ current_page.title }}
        {% endif %}
      </h1>
      

Parameters

None.