Making User Variable From config.toml Show Up In Page Body

888 Views Asked by At

I'm creating a page. I have a site-wide parameter defined in my default config.toml file like this.

[Params]
tdName= "Mr. Tournament Director"

In my page I'm writing:

{{ .Site.Params.tdName }}

Rather than the string in quotes, the code below that is litterally showing up when I run the "hugo server" command. What am I doing wrong?

Thanks.

2

There are 2 best solutions below

0
n m On BEST ANSWER

To specify Go template code in a file in the content directory, you need to use a Hugo shortcode. For example, you could use this inline shortcode:

{{< tdname.inline >}}
{{ site.Params.tdName }}
{{< /tdname.inline >}}

To use inline shortcodes, as I do above, you need to set enableInlineShortcodes to true in your config file.

Note that:

  • site.Params.tdName is usually equivalent to .Site.Params.tdName but is better because it is context free (no leading dot (.))
  • Hugo has some weird case sensitivity issues so I recommend that you change tdName to td_name or tdname or something without upper case characters.
0
n m On

Another option is to use Hugo's built-in param shortcode like this:

{{< param tdName >}}

To learn about this built-in shortcode, see: