I'm trying to get a custom shortcode to output an HTML style tag.
css.html shortcode:
<style class="example-css">
{{ printf "%s" .Inner | safeHTML }}
</style>
sample use:
{{% css %}}
body {
background: green;
}
{{% /css %}}
expected output:
<style class="example-css">
body {
background: green;
}
</style>
actual output:
<style class="example-css">
ZgotmplZ
</style>
Not sure why Hugo is generating that random text. I just need it to pass through the code passed into the shortcode as plain text. Note that if my shortcode uses a div instead of a style tag, it works as expected (but doesn't apply CSS like I need it to).
Please use https://discourse.gohugo.io/ for questions/troubleshooting. Also see Hugo Documentation.
Good to know, thanks!
Since this is the main result when googling this issue, and it never seemed to get asked on the forum:
ZgotmplZ is a string that Go uses to mark a value as unsafe. In this case, you would need to pipe through the safeCSS function, using something like:
<div style="{{ $style | safeCSS }}"></div>
Most helpful comment
Since this is the main result when googling this issue, and it never seemed to get asked on the forum:
ZgotmplZis a string that Go uses to mark a value as unsafe. In this case, you would need to pipe through thesafeCSSfunction, using something like: