Apply multiple templates to same markdown

We’ve got a requirement to render the same markdown to 2 or more different html files.

The basic idea is the main webpage.html is generated as usual, and then we have a print friendly template that will render another.html file.

I can also see this being needed for other types of specific targets like mobile or screen reader layout etc.

Is it possible to do this with Zola as it stands? I can only think of trying to use a taxonomy to try and do this, but this would result in the output being separated and having to coerce the paginator to get what I want.

Ideally I would like to just provide a list of templates in the section.md or page.md and if Zola see’s multiple templates need processing it just loops through them, generating the output to the same directory.

Something like this in my article.md markdown:

template = [“article.html”, “article_print.html”]

With both these templates in the \templates directory as you would expect.

Clearly there might be issues, for example with the slug but in principle is something like this worth including in Zola?

Thanks for reading this far :slight_smile:

It’s not possible right now. Where would the pages be generated since they should refer to the same content/slug/path?

Hi Keats,

It’s not possible right now.

Yes I guessed as much.

If it ever becomes possible I would expect all the templates to render to the default html path for the content being processed. I.e. the output would render to the same path. The slug conflict is more problematic.

Maybe allow for multiple slugs:

slug = ["first-template-slug", "second-temaplate-slug-print-friendly"]
template = ["first-template.html", "second-template-print-friendly.html"]

It’s just an idea, I’m sure there are more elegant solutions that might support backward compatibility for example as I would not want to create any breaking markup | toml changes.

Thanks for giving it a look over though.

Still not solved completely, I also have the problem of paths being splitted but i found a different way without using taxonomies. I write it here, hoping it can help other people.

I’m keeping two subfolders, which share the same .md files, but they use a different template. In order to not having to keep them in sync manually, the files of the second folder are actually hard links to the ones of the first folder.

Symbolic links seems to be ignored by zola, but it works using hard links.

For printing alone, you are already covered by existing standards: Specify a stylesheet with media="print", which is automatically applied when printing the page (as opposed to viewing). Inside this stylesheet, you can do what is needed to make the page printer friendly, such as hiding elements or rearranging them. Simply put, add something like this in your <header>-section:

<link href="print.css" media="print" rel="stylesheet" />

Ref: MDN on Printing | Media types

For other screen types (you mentioned mobile), this is commonly handled in CSS as well. As an example, Bulma reacts to different screen widths (responsive design) as the Bulma docs (just an example, most frameworks do this in one way or the other) explain using this here.


renderingin this case is not Zola’s job here, how the result is presented is the job of the rendering engine (the browser or web component). The way HTML and CSS are designed to function together is such that you won’t have to touch the HTML part, it just gives you structure. How you present it is done in CSS. I managed to get decent results by being a bit careful with the HTML structure and assigning the “designy”-bits to a CSS framework (Bulma), while my media="print"-stylesheet mostly hides elements such as the navbar, search and parts of the footer. Of course, this only works for places where you don’t actually need to have different content presented, and @SgtIria alluded to needing that when they mentioned the paginator, in that case you really need to either go down another route.

@MassiminoilTrace
Hardlinks: <insert complementary warning about different filesystems here> :wink: