Is it possible to use multilevel frontmatter and how?

41 views Asked by At

I'm building Jekyll project. I'd like to use nested frontmatter but cannot figure out why.

---
# Homepage

layout: default
title: Homepage

# links
link1:
 - title: External Link
   url: https://www.example.com
---

and then in my layout:

<a href="{{ page.link1.url }}>{{ page.link1.title }}

This doesn't produce a thing - empty link. How to do it correctly?

1

There are 1 answers

0
Alberto Jiménez On

@Malvinka. In your example, link1 is an Array rather than an object, because of the leading dash "-". See this example with the two ways:

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