Hugo: generating style tag in a shortcode

Created on 31 Jul 2018  路  3Comments  路  Source: gohugoio/hugo

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).

Most helpful comment

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>

All 3 comments

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>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

VoidingWarranties picture VoidingWarranties  路  3Comments

vielmetti picture vielmetti  路  3Comments

sigma picture sigma  路  3Comments

tjamet picture tjamet  路  3Comments

kaushalmodi picture kaushalmodi  路  3Comments