Data variable (with html tag as its value) gives no output


I am using Bootstrap and Font Awesome in my project. I created a popover with content as the data variable. By clicking on button(that triggers popover), popover launches but has no content.

How to reproduce the problem

  1. Create a new Hugo site and add following files with content as given:

data/icons.yml contains:

windows: "<span class='fab fa-windows'></span>"

layouts/index.html contains:

<!-- Bootstrap stylesheet -->
<link rel="stylesheet" href="" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<!-- Font Awesome stylesheet -->
<link rel="stylesheet" href="">

<!-- Scripts required for Bootstrap framework -->
<script src="" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<!-- A popover with Windows icon as its content -->
<a role="button" class="btn" tabindex="0" data-toggle="popover" data-trigger="focus" data-html="true" data-original-title="Tablet" data-content="
 <span class='fa-2x'>{{ | safeHTML }}</span> 

<!-- Enable popovers -->
  1. Now, run hugo serve.

Actual output

It may easily be noted that by clicking on Tablet, popover launches but has no content.

Expected output

The popover should show the Windows icon.

Possible cause

I have found out that I am calling <span class='fa-2x'>{{ | safeHTML }}</span> in quotes (of data-content), so that it renders nothing. If <span class='fa-2x'>{{ | safeHTML }}</span> is called not in quotes, then it renders Windows icon. But that is not how it needs to be. :frowning_face:

Please help!

You’re trying to use Bootstrap to trigger a Popper.js pop-over effect and you’re able to trigger the pop-over dialog but you’re not able to see any content inside the dialog. If that’s correct, have you tried replacing the value of the content data attribute with a string or function as described in the Bootstrap documentation? Also, have you tried including the required util.js?

@balibebas Thanks for quick reply. The problem is highly likely related to Hugo and not Bootstrap or Font Awesome. Let me explain.

Follow the steps

  1. Create a new Hugo site and add following files with content as given:

data/icons.yml contains:

windows: "<span class='fab fa-windows'></span>"

layouts/index.html contains:

<!-- Just an HTML tag (no relation with bootstrap) -->
<a great="
<span class='fa-2x'>{{ | safeHTML }}</span> 

  1. Now, run hugo
  2. Go to public/ and open index.html with a text editor; it contains:
<a great="
  <span class='fa-2x'></span> 

It should’ve contained:

<a great="
  <span class='fa-2x'><span class='fab fa-windows'></span></span> 

This might mean that it is the data variable which is {{ | safeHTML }}) not being rendered.


The HTML syntax in your provided samples is wrong.

The opening <a> tag needs to be closed before the <span> like so:

<a class="whatever" anotherATTR="whatever">
<span class="whatever">
{{ <== Hugo Code ==> }}
Some Text

If you pipe to safeHTMLAttr instead of safeHTML (or if you simply remove the pipe altogether) the missing markup will appear in the generated markup. The output will be escaped like:

<span class='fa-2x'>&lt;span class=&#39;fab fa-windows&#39;&gt;&lt;/span&gt;</span>

And the Font Awesome icon defined in your data file will appear:

@alexandros Thanks for your response. But, I have used Bootstrap popovers and I have to use HTML tags as value of data-content attribute so that Font Awesome icons are displayed correctly.

@balibebas Thanks. It worked! Wonder why my eye didn’t catch it on the Hugo Docs website.