Access Page params in template

Hi,

Sincere apologies if this has been asked/answered (it probably has since its a basic question), but I have been struggling with finding a solution for it for a couple of days.

The basic question: What is the best way to access parameters set in frontmatter from a template/partial? (e.g., .Params.param_name). i.e., how do you get the partial to find the variables associated with the page it is called from?

My specific case is with regard to a carousel template (Slider/Carousel | Hugo Codex). It accesses the image arguments from site data:

 {{ range $index, $slide := .context.Site.Data.carousel.images }}

a yaml file called ‘carousel’ and the type ‘images’ within this file.

However, I would like to have it so that it will use images associated with a particular project so that it can be called on multiple pages with different sets of images. I’ve been trying to set the images in the frontmatter for the project page, but .Params.images (for example) doesn’t seem to find the page parameter.

Any help would be much appreciated! I’m still new to Hugo

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

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.

After spending two days trying to figure it out the solution came to me right after posting this question! It was a very obvious solution in the end.

I just made a separate template for project pages (pages with the carousel) and put the carousel.html directly in there instead of calling it as a partial.