Newbie question (about templates and comments)

Hi,

I currently have a template “header.html” that contains the following block of html:

<div class="trigger">
    <!-- {% for my_page in site.pages %}
      {% if my_page.title %}
      <a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>
      {% endif %}
    {% endfor %} -->
  </div>

As you can see, there’s a big HTML-style comment in the middle of the

.

I thought Hugo would ignore this comment (that comes from a Jekyll site I’m trying to migrate from), but the Hugo server keeps complaining about its contents, specifically it says “function “my_page” not defined”.

How do I get Hugo to truly treat the comment as a comment? Or what’s going on?

I believe you need to comment it out with the same syntax that Go uses. There is a page about comments in the template primer.

Should be like this:

{{/* something to comment out */}}
{{/* 
more to comment out 
*/}}

Untested but:

<div class="trigger">
    {{/* {% for my_page in site.pages %}
      {% if my_page.title %}
      <a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a>
      {% endif %}
    {% endfor %} */}}
  </div>
1 Like