3 ms·
I've found you don't actually need a templating system, you just need format-strings. Write your rendering logic with normal code that just spits out a string
by brundolf 4y ago
I've found you don't actually need a templating system, you just need format-strings. Write your rendering logic with normal code that just spits out a string
Templating languages probably help with performance a bit when you're rendering at request-time, but for static stuff I don't really see much point
I've got a hand-rolled static site generator in JavaScript that just uses template strings. I only have around 30 pages, to be fair, but when I make a change it re-generates the whole site before I can even alt-tab and reload the page. I assume a C++ version could be much faster
- tomjakubowski 4y agoOne great benefit of a good template language is automatic escaping (e.g. within HTML attributes or tags), which you won't get from format strings.
- brundolf 4y agoIs that important in a static site generator? In a server-rendered site you have to worry about injection attacks, but that's not really relevant when you're statically generating a site from content that's fully under your control
- ordu 4y agoBut then you'll need to watch for `<script>` in examples of your articles, so you dont need to write it as `<script>`. And how you are going to get the second in your blog? How do you like to write `&lt;script&gt;`? It is very convenient to have an automatic escaping of everything.
- brundolf 4y agoDepends on the site I guess. My actual blog content is written in Markdown, which already handles escaping stuff between backticks, and that's the only place I'm likely to run into that sort of thing