Templates in content

A very basic, probably stupid, question, but I have not been able to find anything in the docs.

Why is it not possible/allowed to use template instructions in content files, e.g. content/_index.html?

It would be so nice to write things like

{{ $l := [ "foo", "bar" ] }}{{ range $l }}<li>{{.|safeHTML}}</li>{{ end }}


{{ with "someverylongcomplex.url" }}<a href={{.}}>{{.}}</a>{{- end -}}

This works in templates but not in content.

That’s what shortcodes are for.

Templates authors (you) are trusted, but the data you send in is not.

Interesting… For a static site generator I’d consider its data to be trusted as well.

Depends on workflow. For a site where the developer is also the author, sure, trust the data.

But imagine a site, perhaps a school district or magazine, with tens or hundreds of content contributors. Or a site with anonymous contributors. As a developer, there’s no way that I would ever trust the content.

1 Like

I have mixed feelings about this, but I assume this has al been discussed long ago…

Thanks for satisfying my curiosity,

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.