Setting Params on homepage

I have a header partial that loads various javascript snippets when the corresponding param is set. For example, if I need table sorting on a page, then I would just set tablesorter=true in the front matter.

However, I would now like to include a snippet into my homepage, but I can’t find a way to set Params on the homepage. Is there a way to get this working?

Here’s an example of code I’m using in my header partial for including snippets:

{{ if and (isset .Params "toc") (eq .Params.toc true) }}
<script src="/js/generated_toc.js"></script>
{{ end }}

There is no home page params in the same sense as for the content pages, but you can easily set params for the home page in either .Site.Params or in a data file in /data. Have a look in the documentation.

My header partial is included on every page as {{ partial "header.html" .}}. Thus it assumes that every page is able to set params. I could change my header from if param then include this to if homepage and site param or param then include this but that’s not really ideal.

Do you think it would make sense for the homepage to inherit .Site.Params to .Params?

It’s two different things, but it would nice with a Param convenience func.

Your problem is easily solvable with a if statement.


I came up with the following using Scratch.

{{ range $key, $value := .Params }}
{{ $.Scratch.Add $key $value }}
{{ end }}

{{ if $.Scratch.Get "toc" }}
<script src="{{ "js/generated_toc.js" | absURL }}"></script>
{{ end }}

This is included using {{ partial header.html . }} on every page. With this, every page can independently enable inclusion of the Javascript snippet. Regular pages can set params in front matter, and Nodes (not sure on the terminology, but basically the homepage and list type layouts, right?) can use Scratch.

I appreciate the feature request, but I would rather not hugo get bloated up with unneeded convenience functions. I don’t know if other users need such a .Param function or not, but currently I no longer have need of it.

What do you think?

P.S. hugo is great, although the documentation is a bit lacking.

Not sure what that is supposed to solve, but a common use case is to have both a site description and a page description.

{{ .Param "description" }}

Looks bettter than

{{ if .IsPage }}{{  .Params.description }}{{ else }}{{ .Site.Params.description }}{{ end }}

Thanks, this issue can be closed or marked resolved.