I use Hugo to manage this site. It’s pretty cool.

One thing that got me stuck today was passing 2 parameters to a partial.

Since in a partial I could not access .Site.Pages to get the list of pages of the site (due to scope issues), I had to create a dictionary and fill it with 2 items:

{{ partial "my-partial.html" (dict "context" . "pages" $.Site.Pages) }}

The key here is passing (dict "context" . "pages" $.Site.Pages) as the parameter, instead of . as you usually do with partials.

Now inside the partial, instead of using . to access the current context variables you’d use .context.

And to access the value assigned to pages, I’d use .pages.

You can of course pass multiple items, too. Just add more items to the dict.

Did you know?

I have 7 premium training programs that will transform you, quickly, into an excellent Node/React/JS/Vue/Next.js/Svelte developer. Choose your own adventure. Practical lessons to learn the 80% of the things that you need to know, in 20% of the time!

⬇️ ⬇️ ⬇️

Check out all my courses now!

⬆️ ⬆️ ⬆️