Accessing extra data from section template?

zola version: 0.14.1

In the front matter for a paginated section’s _index.md I added an extra data field:

+++
paginate_by = 50
sort_by = "weight"

[extra]
hero_text = "Hello this is my text"
+++

I’ve tried accessing this field in a template as:

  • section.extra.hero_text
  • paginator.extra.hero_text
  • section.hero_text

but none of those work. Is this not how that’s supposed to be accessed? The documentation mentions an extra field for sections so I thought this should work.

Hmm section.extra.hero_text should work, do you have a small reproduction site I can look at?

Hi! I pushed a temporary state here: (link ommited because discourse won’t let me paste three links - it’s the same repo linked below)

This is where I set the field:

And this is where I try to access it: Initial commit (9c5c7810) · Commits · Tamás Szelei / fipsite_temp · GitLab

I had the exact same issue and the problem was that not all of my posts had the [extra] section.

1 Like

Hey sirodoht, your comment helped a lot, thanks. It feels a bit odd though having to add [extra] to all posts. What if that extra data is just for a subset of pages and not all pages. Are there other ways to achieve this?

It seems you’re close! Try accessing the extra field like this in your template:

html

{{ section.extra.hero_text }}

If that still doesn’t work, ensure that your _index.md is being treated as a section and not a regular page. Also, double-check for any typos in your front matter.