How to wrap Hugo code in comments?

For example

{{ else }}
    {{- warnf "missing cover image for page %s" . -}}
  {{- end }}

because this does not work

 {{-/* 
   {{ else }}
    {{- warnf "missing cover image for page %s" . -}}
 /*}}

I’m not sure what that means. Bit if you’re starting with something like this:

{{ if false }}
  {{ warnf "%s" "false" }}
{{ else }}
  {{ warnf "%s" "true" }}
{{ end }}

This works great:

{{ if false }}
  {{ warnf "%s" "false" }}
{{ else }}
  {{/*  {{ warnf "%s" "true" }}  */}}
{{ end }}

And so does this:

{{ if false }}
  {{ warnf "%s" "false" }}
{{/*  {{ else }}
  {{ warnf "%s" "true" }}  */}}
{{ end }}

The terminal claims the comment is unclosed. parse failed unclosed comment

Then your actual code doesn’t match what I’ve shown above, or the error is coming from someplace else.

Your end delimiter is wrong use */ }} instead

One of my common pitfalls :wink:

You are right! Talk about a simple mistake. /* instead of */ in the closing comment. Took me a while to debug it.

@irkode true! I spent close to 40 minutes on it. lol. (That section of your code Error: Can't evaluate field RelPermalink in type string - #2 by irkode was throwing warnings for draft posts. Hence the need to comment it out and only use it when necessary).

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.