.Title in range of shortcode

Hello,

I try to use the title of pages in a shortcode, e.g. {{ range .Site.Data.states.TITLE.somejson.foo }}

Scenario:
I have several hundred json data files and for each a page. Every page has the same fields but with different values, hence the shortcode. The json files are named after the title of the page.

So is it possible to use the title variable (.Title) in the path of range in the shortcode?

Thanks!

Use the index function.

{{ range index site.Data.states (lower .Title) "somejson" "foo" }}
1 Like

I tried that but missed the lower…My bad.

Thanks, ~this works!~

EDIT: It does not.

Sorry, I tried the index with an actual name of a title. That worked. However, when I try the syntax with (lower .Title) hugo fails with:

can't evaluate field Title in hugolib.ShortcodeWithPage

{{ index .Site.Data.states (lower .Page.Title) “data” “persistentUrl” }} works.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.