I’m getting an error trying to use the templating tags.
For example, if I put this in my Markdown file
{{ with .Site.LanguageCode }}{{ . }}{{ else }}en-US{{ end }}
I get this output:
<p>{{ with .Site.LanguageCode }}{{ . }}{{ else }}en-US{{ end }}</p>
It doesn’t run the function.
You cannot do that.
You can have only Shortcodes ({{< foo >}}
or {{% bar %}}
) in content files.
The Go templating snippet you pasted would work only in layout files (files in layouts/
or themes/
).
1 Like
If you were writing this in a template, a bit more succinct form of the above is:
{{ .Site.LanguageCode | default "en-us" }}