RSS

Hugo: How to escape shortcode in markdown

Hugo: How to escape shortcode in markdown to display as literal text.

Problem with shortcode like text in Hugo markdown

In Hugo markdown, if you have some text wrapped by curly brackets likes following:

Today: {{%m%d%y}}

You will receive an error similar to the following:

Error: Error building site: "foo.md:36:25": failed to extract shortcode: template for shortcode "m" not found

This is due to Hugo treat {{%m%d%d}} as its shortcode .

A shortcode is a simple snippet inside a content file that Hugo will render using a predefined template. In your content files, a shortcode can be called by calling {{% shortcodename parameters %}}.

Solution on how to escape shortcode in Hugo markdown

Solution 1: Add space between {{ (curly bracket) and %.

Today: {{ %m%d%y }}

Solution 2: Escape % with unicode in HTML

If you don’t want extra space between {{ and %, you can escape % with %. Example:

Today: {{%m%d%y}}

This trick is being used by this page.

Solution 3: Use /* */ comment

Use /* */ to quote the comment shortcode.

{{< myshortcode param1="value1" param2="value2" >}}

Related pages:

References

OmniLock - Block / Hide App on iOS

Block distractive apps from appearing on the Home Screen and App Library, enhance your focus and reduce screen time.

DNS Firewall for iOS and Mac OS

Encrypted your DNS to protect your privacy and firewall to block phishing, malicious domains, block ads in all browsers and apps

Ad