DEV Community

Cover image for Hugo Shortcode to Render HTML
Shekhar Chandra
Shekhar Chandra

Posted on

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

Top comments (0)