Eleventy: How do I access front matter data of the current page?

Created on 20 Aug 2020  路  3Comments  路  Source: 11ty/eleventy

I'm migrating a Jekyll site to Eleventy using Liquid templates.

In Jekyll, it's possible to access the current page's front matter data in a layout simply by using the page variable. For instance, I can print the page title using {{ page.title }}. I understand that in Eleventy front matter is stored under data, but {{ page.data.title }} gives me nothing, and indeed the entire data key seems to be missing.

What's the intended way to access front matter data of the current page (in a layout)?

education

Most helpful comment

I'm not sure how much the template engine impacts this, but in liquid I just use {{ title }} to get the title: item from the front matter. I only use the .data. method when working with data from collections.

All 3 comments

I'm not sure how much the template engine impacts this, but in liquid I just use {{ title }} to get the title: item from the front matter. I only use the .data. method when working with data from collections.

Ah, you're right. Thank you!

It is in my opinion somewhat unintuitive that page doesn't have the same structure as when reading it from a collection. Adding to the confusion is that both "collection" and "current" forms of the page contain some of the properties I would expect, like date and url, with the former also defined in the front matter.

I'm closing this as my question was answered.

It is in my opinion somewhat unintuitive that page doesn't have the same structure as when reading it from a collection.

@proog You may be interested in #338.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smaimon picture smaimon  路  3Comments

AjitZero picture AjitZero  路  3Comments

michrome picture michrome  路  3Comments

kaloja picture kaloja  路  3Comments

jamrelian picture jamrelian  路  3Comments