What does the `$` do?

I got a code from _internal

{{ $pag := $.Paginator }}

And because I’m not Go dev so I can stop wondering what $ does in the code?

Which ‘$’ are you referring to?

If you’re asking about $pag, the ‘$’ is how variables are named.

If you’re asking about $.Paginator then it’s the way you reference the global scope (link to docs).

1 Like

$ is the root context of your template file. Any template file.

From within a partial, from within a layout, from within a Shortcode, $ is the root context.

Because in Go Template, within function like with, range and other the context (the dot) is reset to theirs, it is handy to have the root context stored in $.

:point_right: https://regisphilibert.com/blog/2018/02/hugo-the-scope-the-context-and-the-dot/#the-top-level-context