3 ms·
I've found Handlebars to be the sweet spot for templating. Mustache is too limited for my taste and seems to force me to pre-render parts of the HTML, so that
by kennu 14y ago
I've found Handlebars to be the sweet spot for templating.
Mustache is too limited for my taste and seems to force me to pre-render parts of the HTML, so that the template doesn't actually contain all of it. Or there will be many small templates, being combined by some logic that's not clearly visible when looking at the template code.
Handlebars has just enough flexibility to allow me to put all HTML in a single template, using {{#if}} and {{#each}} to navigate the data. Then I can add helpers and new data model properties to add formatting and logic.
The sweet spot of logic for me means that I only use a single identifier in the {{#if}}, such as {{#if adminAccess}}, and make "adminAccess" a property of the data model. So then whoever reads the template is not trying to parse huge logical expressions in the if clauses, but only sees their results assigned to identifiers.
(Earlier, Mustache was even more limited, because it didn't have the concept of "this" ({{.}}) when iterating arrays. As I understand, this has later been fixed.)