我正在构建 Jekyll 项目。我想使用嵌套的 frontmatter 但不明白为什么。
---
# Homepage
layout: default
title: Homepage
# links
link1:
- title: External Link
url: https://www.example.com
---
然后在我的布局中:
<a href="{{ page.link1.url }}>{{ page.link1.title }}
这不会产生任何东西——空链接。如何正确做?
@马尔文卡。在您的示例中,由于前导破折号“-”,link1 是一个数组而不是一个对象。请参阅此示例的两种方式:
---
layout: error
description: Sorry – the page your looking for doesn't exist.
permalink: /404.html
linkArr:
- title: External Link1
url: https://www.example.com
- title: External Link2
url: https://www.dfswedf.com
link1:
title: External link4
url: https://www.ei4.com
---
{% assign urlM = page.linkArr | first | map: "url" %}
<script type = 'text/javascript'>
console.log(" url arr {{ urlM }}");
console.log("url obj {{page.link1.url}}")