首页 > 技术文章 > liquid 对象

-LemonWater- 2021-08-20 17:18 原文

对象: {{ variable }}

{{ page.title }}
变量赋值
  • <% assign %>

  • <% capture %>

    ( 开始符与结束符之间的字符串赋给capture的变量 )

    <!-- assign 赋值 -->
    {% assign favorite_food = 'pizza' %}
    {% assign age = 35 %}
    
    <!-- capture 赋值 -->
    {% capture about_me %}
    I am {{ age }} and my favorite food is {{ favorite_food }}.
    {% endcapture %}
    
    {{ about_me }}
    -----------------------------
        output: I am 35 and my favourite food is pizza.
    
  • <% increment %>

    ( 递增变量 ,初始值1 )
    {% assign var = 10 %}
    {% increment var %}
    {% increment var %}
    {{ var }}
    
    ----------------------
        output: 1 2 10
    
  • <% decrement %>

    ( 递减变量 ,初始值-1 )
    {% capture variable %}10{% endcapture %}
    {% decrement variable %}
    {% decrement variable %}
    {{ variable }}
    
    -----------------------------
        output: -1 -2 10
    
    注意: 在 `increment``decrement` 之中创建的变量与通过 `assign` 或 `capture` 创建的变量是互相独立的。

推荐阅读