<ul class="{{ if .tree }}tree{{ end }}">
  {{ $currentPage := .ctx }} 
  {{ $isTree := .tree }}
  {{ range site.Menus.main }}
  <li>
    {{ $isActive := eq .Page $currentPage }}

    {{ range .Children }}
    {{/* Also make active in case a child is active */}}
    {{ $isActive = or $isActive (eq .Page $currentPage) }}
    {{ end }}

    <a href="{{ .URL }}" class="{{ if $isActive }}active{{ end }}">
      {{ .Name }}
    </a>

    {{ if .HasChildren }}
    <ul class="submenu">
      {{ range .Children }}
      <li class="submenu">
        <a
          href="{{ .URL }}"
          class="{{ if eq .Page $currentPage }}active{{ end }} submenu"
          >
          {{ .Name }}
        </a>
      </li>
      {{ end }}
    </ul>
    {{ end }}
  </li>
  {{ end }}
</ul>
