sitewriter
sitewriter copied to clipboard
Allow for logic for use within templates
Looking at the following example:
categories:
{{#categories}}
- {{name}}
{{/categories}}
Should the user not have provided any categories, the categories
key will be output regardless. The ability to use limited template logic would provide finer grained control over the template output. So, for example, the above example could be written as:
{{#if categories}}
categories:
{{#categories}}
- {{name}}
{{/categories}}
{{/if}}
It’s a small thing, but something worth recording, I thought.
(That said… having just written this issue, maybe it’s already possible? In which case, it would to provide some help text about what template syntax is available).
The template language is Mustache, which is not good at this. But I can introduce a property like has_categories
to support it. (In fact, there is a has_photos
already for one of my templates.)
I might switch to Liquid for templates, anyway, which will make this easier and will be familiar to Jekyll users.
But this use case might become moot if we get more explicit about handling metadata in front matter. This would be necessary for features that add new metadata, like webmentions.
See also #37