Using a site global string

I am using some string in many pages on the site, so I want to set it to a global variable and reference to it somehow. I have started to tackle this with site variables, but I can not get the variable to be used in the content. Is this the way and I am missing something or there is another?

Up until an hour ago the answer to your question would be: no

However since Hugo 0.52 there is a new feature called Inline Shortcodes:

that allow ad-hoc Go Text templates to be executed from the content files

So this might help you achieve what you need. You can read the newly released Doc over here:

So now I can use site variables like this {{< .Site.params.something />}} ?

Have a look at the new param shortcode (in Hugo 0.52 just out).

1 Like

Right. Here is the relevant commit:

The param shortcode is different than the Inline Shortcodes that I mentioned above and it looks like it’s exactly what you need @tyacbovi

Just took it for a spin and this is cool :slight_smile:


@tyacbovi say you had this in your config.toml

[params]
  globalString = "Rocks!"

Then you could reference the global string like

---
title: "Some Page"
---

Hugo {{< param globalString >}}

Be sure to checkout the examples linked by the others above as well

5 Likes