Hugo Shortcode to Render HTML

ranuzz

Shekhar Chandra

Posted on July 14, 2021

Hugo Shortcode to Render HTML

Problem

Adding raw HTML in hugo content doesn't render at all in static page.

Solution

Add a shortcode in layout folder to handle HTML in a safe manner.

<!-- renderhtml.html -->
{{- $content := .Get "content" | default (.Get 0) -}}
<div>
    {{ $content | safeHTML }}
</div>
Enter fullscreen mode Exit fullscreen mode

Now it can be included in any mardown content file as, Just put the raw HTML in between the ticks.

{{ < renderhtml `<div></div>` >}}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
ranuzz
Shekhar Chandra

Posted on July 14, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related