Can't load Page Frontmatter When Using Range

I’m unable to render my custom frontmatter value while using range in a partial. This is what my frontmatter looks like:

feature: whatsapp.png
Title: Srishti '23, Unwrapped
summary: A data analysis of 20,000+ messages in the Srishti '23 Whatsapp group, visualized.
slug: whatsapp

I want to pull the feature value into my partial, called latest.html in the following code:

{{ $section := site.GetPage "projects" }}
{{ range first 1 $section.RegularPages }}
            <a href="{{ .Permalink }}">
                <img alt="post photo" src="/{{ .Params.feature }}"/>
                        {{ .Title }}
                        {{ .Summary }}
{{ end }}

{{ .Params.feature }} does not load anything. When I put in whatsapp.png, the image loads so I know its not a path problem. Can someone tell me what is going front here?

You see in the formatting of the markup here in the forum, that there is something wrong. And I would guess it’s the apostrophe before 23. Quick fix: add quotation marks.

Title: "Srishti '23, Unwrapped"
summary: "A data analysis of 20,000+ messages in the Srishti '23 Whatsapp group, visualized."

No luck :confused: The title and summary and slug are rendering fine though, only the custom parameter is a problem. I’m guessing it is something to do with it not being default and so $section must have some other way of declaring it.

This is my repo, if it helps

You forgot to pass the . dot context.

1 Like

I have made this change:

</span> {{- partial "latest.html" . -}} {{- partial "projects.html" . -}} {{ partial "blogs.html" }}

Is this what I was supposed to do? I still don’t see the image.

When I run your code, the image is there just fine:

1 Like

I accidentally pushed a commit without the {{ .Params.feature }}, you are loading the image directly in the code if you see (notice whatsapp.png in the img src)?

It should be this:

<img alt="post photo" src="{{ .Params.feature }}" class="max-h-80 w-full object-cover" />

I’m reversing the commit.

EDIT: This works!

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