Help with fundamental understanding of Maps in Hugo/Optimal uses

I’ve been trying to pull data out of frontmatter

featured_post:
 post_options:
   -  title: 'test'
      date: 2022-08-10 10:00:00 -0700

On the one case I am able to pull out data using a range:

  {{range $p := where .Params.featured_post.post_options "date" ">=" .Date }} 
       <div>{{$p.date}}</div>
  {{end}}

Coming from other languages I would have expected dot notation to work and not to have to range over the data to get one value from a series of keymap pairs. As it scales optimization is important so a more efficient way would be helpful.

But more confusing to me is that using isset isn’t working.

{{if isset .Params.featured_post.post_options "date"}}
  <div>Found!</div>
{{end}}

These issues make me feel like I’m missing a piece of the puzzle in comparison to what I’m used to when dealing with maps. Any help/ readings/ notes would be much appreciated.

Your example works fine for me. Can you share your project with us?

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

I keep getting this error

post_options is not a method but has arguments

Like I said…

Your example works fine for me. Can you share your project with us?

It is going into production so I will not be sharing it and recreating a demo is a bit much; however, I realized it is due to the post options being a list which each item in the list is a map.

Gotcha. I can see that you edited your original post; thank you for making the correction.

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