Use variable inside Hugo content

So it looks like a shortcode is the way to do this. For what it's worth, I changed the document to look like the following:

  1. Go to your site's url ({{< siteurl >}})

In layouts/shortcodes, I created the file siteurl.html. It looks like the following:

{{ .Page.Site.BaseURL }}

I needed to add .Page in there to get access to the Site variables. See this Issue Report for more details.


In Hugo, When you want to use a variable in markdown (.md) file then you need to create a shortcode for that first.

You can follow these steps:-

create shortcode

layouts/shortcodes/siteurl.html

{{ .Page.Site.BaseURL }}

usage

content/post/myblogpost.md

---
# front-matter
---
1. Go to your site's url ({{< siteurl >}})
2. Enter your credentials
3. .....(blah blah blah)

result

post/myblogpost.html

1. Go to your site's url (https://codingnconcepts.com)
2. Enter your credentials
3. .....(blah blah blah)

Source: https://codingnconcepts.com/hugo/custom-shortcode-hugo/