The last of the menu items

{{ range .Site.Menus.xxxx}}
    <li><hr class="dropdown-divider"></li>
{{ end }}

How can I make the last children not contain this separator?

Is there a way to do this?
isMenuChildrenLast OR isChildrenLast

Perhaps you can do that with CSS instead of hard HTML :thinking: With something like:

li:after {
  border-bottom: solid 1px black;
}
li:last-child:after {
  border-bottom: none;
}

Thanks, that doesn’t suit the current needs, although it can be achieved.

Compare the element key to the length of the array/slice:

{{ $s := slice "a" "b" "c" }}
{{ range $k, $v := $s }}
  {{ $v }}
  {{ if lt $k (sub (len $s) 1) }}
    <hr>
  {{ end }}
{{ end }}
1 Like
<ul>
{{ $len := len .Children }}
{{ range $k, $v := .Children }}
    {{ if .HasChildren }}
        ...
    {{ else }}
        ...
    {{ end }}
    {{ if lt $k (sub $len 1) }}
        <li><hr class="dropdown-divider"></li>
    {{ end }}
{{ end }}
</ul>

According to your tips, writing like this can meet the requirements. There is no separator after the last one.