[solved] Using partials within xml files (RSS template)

Can we use partials from within an xml template file ?

I am currently customizing the index.xml template file for RSS and I am not sure about the syntax to use with partials or if it’s possible in the first place ?

{{ partial "path/to/partial.xml?" .}}

What are you trying to do?

Partials end with .html, but they are Go templates, so you should be able to use {{ partial "path/to/partial.html" . }} just as well to accomplish what you want.

The embedded rss.xml is a Go template as well. You can just add partials as normal, not ending .xml. :slight_smile:

Partials can end with .html

It is true that we fallback to .html as a last resort, but we first try the name as-is.

So if you write:

{{ partial "mypartial.xml" . }}

That will work.

Also, if the suffix used resolves to an output format that is defined as “text only” (isText=true), it will be parsed by Go’s text template package, which can avoid some surprises with Go’s HTML escaping.

3 Likes

Great thanks @bep :slight_smile: