Search code examples
hugotoml

is not a field of struct type hugolib.SiteInfo in


I tried adding a new property to my theme/partials/footer.html template, and adding that property to my /config.toml file, but I keep getting the error:

ERROR: 2017/07/09 template: theme/partials/footer.html:16:40: executing "theme/partials/footer.html" at <.Site.CopyrightStart...>: CopyrightStartYear is not a field of struct type *hugolib.SiteInfo in theme/partials/footer.html

Example from my partial template file:

<span>&copy; {{.Site.copyrightStartYear}}</span>

Solution

  • The template engine in Hugo will look for all site params under the [Params] block in the config.toml file (must be a quoted string for this example). These can be referenced via the .Site.Params.<paramName> lookup in partial templates.

    e.g.

    # config.toml
    ...
    [Params]
        myParam = "weeee!"
    ...
    

    And use it in your HTML fragment:

    # somePartial.html
    <span>{{ .Site.Params.myParam }}</span>
    ...