Skip to content

Dashes in global data variable names #567

@paulrobertlloyd

Description

@paulrobertlloyd

Given the following frontmatter:

fruit: Apple
is-it-tasty: Yes

I can access the first value within a collection loop using the item.data.fruit variable, and on pages by using fruit.

For the second value, given its hyphenated nature, I’ll need to use the bracket notation. Within a collection loop I can access it using item.data['is-it-tasty'], but how can I access this value on a page? I tried page.data['is-it-tasty'], but that didn’t work, nor did data['is-it-tasty']. What’s the expected approach?

(Side note: the apparent discrepancy between item.data.thing within loops, and just thing on pages keeps tripping me up 🙃.)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions