What does the `$` do?

$ 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

2 Likes