代码之家  ›  专栏  ›  技术社区  ›  Somenath Sinha

如何在变量中创建自定义液体变量(即自定义液体对象)?

  •  0
  • Somenath Sinha  · 技术社区  · 8 年前

    让我们考虑以下代码:

    ---
    layout: post
    title:  "Welcome to Jekyll!"
    test:
      name: google.com
    ---
    
    {{ post.test.name }}
    {% assign addr="https://www.google.com" %}
    
    # Heading
    This is a link to [the Google homepage!][ghome]
    This is another link that [may or maynot work][glink]
    
    
    [ghome]: https://google.com
    [glink]: {{ addr }}
    

    正确输出:

    Output1

    然而,当我尝试做同样的事情,但改变 addr test.addr (从而将其转换为 test ,链接断开:

    broken object

    1. 我如何使上述工作?!
    2. 如何向变量添加新属性 page.test 这一页的首页描述了哪些内容?
    1 回复  |  直到 8 年前
        1
  •  2
  •   ashmaroli    8 年前

    Page ,数据向一个方向流动。

    Front Matter => Content

    您可以执行以下操作:

    {% assign addr = page.test.name %}
    
    [link][glink]
    [glink]: {{ addr }}
    

    但是 您不能执行以下操作 :

    {% assign page.test.addr = "https://www.google.com" %}
    
    [link][glink]
    [glink]: {{ page.test.addr }}