sitewriter icon indicating copy to clipboard operation
sitewriter copied to clipboard

Allow for logic for use within templates

Open paulrobertlloyd opened this issue 6 years ago • 2 comments

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).

paulrobertlloyd avatar Mar 29 '18 19:03 paulrobertlloyd

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.

gerwitz avatar Mar 30 '18 13:03 gerwitz

See also #37

gerwitz avatar Apr 22 '18 20:04 gerwitz