Liquid 문법

1. Liquid 핵심 요소

Liquid 코드는 object, tag, filter의 세가지로 정리할 수 있다.

1.1. Object

{{}}로 object와 변수를 사용한다.

input

1
{{ page.title }}

output

1
Introduction

1.2. Tag

{%%}로 tag를 사용한다. Liquid 문법 구성에 사용된다.

input

1
2
3
{% if user %}
  Hello {{ user.name }}!
{% endif %}

output

1
Hello Adam!

Tag는 다시 세 가지로 나뉜다.

1.2.1. Tag - Control flow (분기)

1.2.2. Tag - Iteration (반복)

1.2.3. Tag - Variable assignments (변수)

1.3. Filter

파이프 |를 이용해 object와 변수의 출력형식을 지정한다.

input

1
{{ "/my/fancy/url" | append: ".html" }}

output

1
/my/fancy/url.html

filter는 중첩가능하다.

input

1
{{ "adam!" | capitalize | prepend: "Hello " }}

output

1
Hello Adam!

2. Liquid 기타 요소

2.1. 연산자

  • 기본 연산자
== eq
!= neq
> gt
< lt
>= gte
<= lte
or or
and and
  • contains 문자열 탐색 연산자이다.
1
2
3
{% if product.title contains "Pack" %}
  This product's title contains the word Pack.
{% endif %}
1
2
3
{% if product.tags contains "Hello" %}
  This product has been tagged with "Hello".
{% endif %}

*기타

  truthy falsy
true v  
false   v
nil   v
string v  
empry string v  
0 v  
integer v  
float v  
array v  
empty array v  
page v  
empty drop v  
Comment