{{ $slug := .Slug }} {{ if not $slug }} {{ $slug = .File.BaseFileName }} {{ end }} {{ $path := printf "comments/posts/%s/export.html" $slug }} {{ $fallbackPath := "comments/resources/fallback.html" }} {{ if fileExists $path }} {{ readFile $path | safeHTML }} {{ else }} {{ if fileExists $fallbackPath }} {{ $key := (printf "%s.html" $slug) }} {{/* as far as I can tell, this jankiness is the best way to dynamically include templates */}} {{ $r := readFile $fallbackPath | resources.FromString $key }} {{ $out := $r | resources.ExecuteAsTemplate $key (dict "Page" . "slug" $slug) }} {{ $out.Content | safeHTML }} {{ end }} {{ end }}