HUGO

Custom Variables

Hi, how can I define my own global variables to pass from template to template? Similar to how you can call everywhere “.Site.Home” and others. I need to store the state of the navbar. (JS is not an option, since I will have to rewrite part of the navigation)

Hugo is a static site generator—stateless by definition.

As a single page is rendered to HTML, each template that forms the page (header, nav, main, sidebar, footer) can:

  • Access global custom parameters (read only)
  • Create and pass a value to another template. For example, a header template might create and pass a value to the sidebar template.

But the end product is still a static HTML page. There are no session variables as you might find in a dynamic site. It sounds as if you might need to use JS to create/read/write cookies.