Using a site global string


#1

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?


#2

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:


#3

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


#4

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


#5

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


#6

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


Variables in markdown