This works fine, but is very verbose. And lots of brackets. Any ideas?
I’m reading headings (“tags”) and page slugs (“topics”) from a data file. I only want to create each heading if the named pages actually exist.
{{ range $tag := .Site.Data.tags }}
{{ $topics := index $tags_and_topics $tag }}
{{/* */}}
{{/* Skip this tag if there are no pages under it. */}}
{{/* */}}
{{ $has_a_page := false }}
{{ range $topic := $topics }}
{{ $topic_slug := lower (replace $topic " " "-") }}
{{ $page := $.Page.GetPage $topic_slug }}
{{ if $page }}
{{ $has_a_page = true }}
{{ end }}
{{ end }}
{{ if not $has_a_page }}
{{ continue }}
{{ end }}
<h2>{{ i18n $tag }}</h2>
<ul>
...
{{ end }}