제어 흐름 태그
제어 흐름 태그는 주어진 조건에 따라 실행해야 할 코드의 블록과 렌더링할 콘텐츠를 결정합니다. 조건은 사용 가능한 유동 연산자를 사용하여, 또는 단지 주어진 값의 진실 또는 허위에 따라 구축됩니다.
if
주어진 조건이 충족되면 코드 블록을 실행합니다.
{% if user.fullname == 'Dave Bowman' %}
Hello, Dave.
{% endif %}
unless
주어진 조건이 충족되지 않으면 코드 블록을 실행하는 것을 제외하고는 if와 같습니다.
{% unless page.title == 'Home' %}
This is not the Home page.
{% endunless %}
elsif/else
if 또는 unless 블록에 더 많은 조건을 추가합니다.
{% if user.fullname == 'Dave Bowman' %}
Hello, Dave.
{% elsif user.fullname == 'John Smith' %}
Hello, Mr. Smith.
{% else %}
Hello, stranger.
{% endif %}
case/when
변수를 다른 값들과 비교하여 각 값에 대해 다른 블록의 코드를 실행시키는 전환 명령.
{% case user.fullname %}
{% when 'Dave Bowman' %}
Hello, Dave.
{% when 'John Smith' %}
Hello, Mr. Smith.
{% else %}
Hello, stranger.
{% endcase %}