ホワイトスペース制御

リキッドで、タグ構文 {{--}}{%--%} にハイフンを挿入して、レンダリングされたタグの左または右側の空白を消去できます。

通常、テキストを出力しない場合でも、テンプレートの Liquid の行はレンダリングされた HTML に空行を出力します

入力

{% assign my_variable = "tomato" %}
{{ my_variable }}

レンダリングされたテンプレートの「トマト」の前にある空行に注意してください

出力


tomato

assign の終了デリミタにハイフンを挿入して、それを続く空白をレンダリングされたテンプレートから消去できます

入力

{% assign my_variable = "tomato" -%}
{{ my_variable }}

出力

tomato

すべてのタグに出力空白がないようにするには、すべてのタグの両側にハイフンを追加できます ({%- と、 -%})

入力

{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
  Wow, {{ username }} , you have a long name!
{% else %}
  Hello there!
{% endif %}

空白制御なしの出力



  Wow, John G. Chalmers-Smith , you have a long name!

入力

{% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
  Wow, {{ username -}} , you have a long name!
{%- else -%}
  Hello there!
{%- endif %}

空白制御ありの出力

Wow, John G. Chalmers-Smith, you have a long name!