If statement and html

Hi all,

I have been migrating from Jekyll to Hugo (and I’m doing pretty good so far!). But I have a small problem. I have been using this code on my template but I can’t find a way to translate it in Go.

I know the conditional statements have a different syntax with Go and I’ve been reading about that, but I can’t find the solution.

Thanks a lot for your help

 <li {% if page.url == "/index.html" %}class="active"{% endif %}>
                    <a href="index.html">HOME</a>

A basic comparison construct…

{{ if eq $var1 $var2 }}
{{ end }}

The same, but inline…

{{ if eq $var1 $var2 }}...{{ end }}

If you are ranging through pages and want to handle the home page differently…

{{ range .Site.Pages }}
  <li {{ if .IsHome }}class="active"{{ end }}>
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
{{ end }}

Based on lack of context, what you are trying to accomplish is unclear.

1 Like

Thank you. This is exactly what I needed. :grinning:

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