DEV Community

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

Posted on

1 1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay