I have two differently styled child menus built using unordered lists.
I’d like to hide the whole blue section of sublinks if the .Param.sublink is not set.
{{- range .Site.Menus.primary }}
{{ if .HasChildren }}
<div>
<ul class="linkGroup">
{{ range .Children }}
{{ if .Params.sublink }}{{ else }}
<li>
<a href="{{ .URL }}">{{ .Name }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</div>
<ul class="sublinkGroup">
{{ range .Children }}
{{ if .Params.sublink }}
<li>
<a href="{{ .URL }}">{{ .Name }}</a>
</li>
{{ else }}
{{ end }}
{{ end }}
</ul>
{{ end }}
{{ end }}
How do I go about hiding/not displaying the whole <ul class="sublinkGroup"> block if no child menus have .Params.sublink?
I’ve tried encapsulating the ul block inside {{ if .Params.sublink }} <HTML>{{ else }}{{ end }} like I have for the range but that doesn’t work. Also tried {{ if isset .Params "sublink" }} in the same manner but that doesn’t work either.
Any ideas? Also open to coding this and entirely different way if I’m going about achieving this in the wrong way.
I did try this but it doesn’t work. The whole ul block is not shown whether any child menus have .Param.sublink set or not. And I don’t understand why because the code looks logical to me.
P.S. Lack of sleep could well be a factor!
P.P.S. Primary goal is to only show the blue area in the menu if any child menus in the config.toml' have .Param.sublink` set to true.
{{ $sublinks := where .Children ".Params.sublink" "=" true }}
{{ if $sublinks }}
<ul class="sublinkGroup">
{{ range $sublinks }}
<li>
<a href="{{ .URL }}">{{ .Name }}</a>
</li>
{{ end }}
</ul>
{{ else }}
{{ end }}
Thank you so much for your help @RHEV
Again if you (or anyone else thinks there's a better way to achieve this please do comment.)