【问题标题】:How can we create custom liquid variables within variables (i.e., custom liquid objects)?我们如何在变量中创建自定义液体变量(即自定义液体对象)?
【发布时间】:2018-06-19 09:59:39
【问题描述】:

让我们考虑以下代码:

---
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 }}

正确输出:

但是,当我尝试做同样的事情但将 addr 更改为 test.addr (因此将其转换为test 的数据成员,链接断开:

  1. 我该如何进行上述工作?!
  2. 如何向页面前面描述的变量page.test 添加新属性?

【问题讨论】:

  • 第二个示例的代码是什么? linkcontainer 来自哪里?
  • @DavidJacquel 它们是我正在尝试创建的自定义变量和对象(分别)..
  • 您想用container.link 替换test.name 吗?
  • @DavidJacquel 很抱歉造成混乱,我已经澄清了我的问题。链接是指包含链接的变量,容器是对象test
  • 您不能修改在 config 或 front matter 中创建的对象。

标签: jekyll liquid yaml-front-matter


【解决方案1】:

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 }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-04
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 2011-11-07
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多