{{.Params.value}} not working inside the range

I don’t know the reason why {{.Params.value}} is not working inside the range

Here the example

---
title: "Some File"
url: /some-file
author: "Rahul"
breadcrumbs:
 - name: "Trail #1"
   url: "/url-for-trail-1"
 - name: "Trail #2"
   url: "/url-for-trail-2"
 - name: "Trail #3"
   url: "/url-for-trail-3"
---
       {{range .Params.breadcrumbs}}
               <p>{{.name}}</p>
               {{.Params.author}} 
       {{end}}

In here why {{.Params.author}} is not works?

It’s referring to Params.breadcrumbs.Params.author since range changes what dot refers to.

2 Likes

@chrillek is correct, so what you want is:

{{ range .Params.breadcrumbs }}
  <p>{{ .name }}</p>
  {{ $.Params.author }} 
{{ end }}

See https://gohugo.io/templates/introduction/#context

The most important concept to understand before creating a template is context

Make sure that you thoroughly understand the concept of context before you continue reading. The most common templating errors made by new users relate to context.

1 Like

@jmooring and @chrillek , I can use breadcrumb values within the range. However, I also need to access other values such as title, author, and URL within the range. If we can’t access other frontmatter values within the range, we should display an error message, right?

Please read @jmooring‘s post again. Carefully. And research „Hugo context“ with your favorite search engine. That should reveal blog entries by Regis which are enlightening.

1 Like

thank you so much @chrillek and @jmooring $. helps good learning

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