HUGO

Naming convention for page context (within a dictionary) when calling partial: seeking opinions

When passing the current page context (within a dictionary) to a partial, which of the following naming conventions do you use, and why? Or do you use something different?

#1 {{ partial "my-partial.html" (dict "context" . "foo" "bar") }}
#2 {{ partial "my-partial.html" (dict "ctx" . "foo" "bar") }}
#3 {{ partial "my-partial.html" (dict "page" . "foo" "bar") }}
#4 {{ partial "my-partial.html" (dict "Page" . "foo" "bar") }}

This frequently cited article by @regis suggests #4.

There’s no right answer for this; I’m just looking for a best practice to clean up inconsistent usage across several projects.

I did not understand his article for this to be “the right” way. it’s just something he does this way.

In my own partials when doing a dictionary I am not handing over the dot, but re-requesting what ever I need globally with for instance site. or $. or whatever global way is available.

If I would have a case to have a page context in a dictionary for a partial I would probably prefer #3, because all parameters would be lowercased, it would be the actual page and ctx or context are basically terms that developers understand, but maybe not the end-user of the partial.

That’s just an opinion. In the end, the documentation of your partial will tell people what term to use :stuck_out_tongue:

Also: that partial might not always be in a “page context”, so calling the “dot” page or context might be very specific to certain use cases?

I like .Page because first uppercase makes it very hugo, reminding the user it’s a Page object and not a regular input of data like a slice or a map. I use that most of the time, but it’s not always 100% accurate. If your page object resonate more as something else like a page bundle with resources… Then maybe .Page will not do.

2 Likes