Handlebars
Syntax
The most of the syntax should be the same as handlebars, but with some improvements.
Variables
You can render variables in the template using the following syntax:
{{ variable }}
{{ variable.property }}
Block helpers
if
Render conditionally
{{#if nullable_variable as variable }}
<!-- do something, variable is defined here as nonnullable of `nullable_variable` -->
{{else if other_nullable_variable as variable }}
<!-- do something else if, variable is defined here as nonnullable of `other_nullable_variable` -->
{{else}}
<!-- do something else -->
{{/if}}
Each (loops)
Iterate over lists and render the content for each item
{{#each variable as item }} <!-- `item` can be any identifier -->
<!-- do something with each iteration -->
<!-- the iterations item is available in `item` -->
{{ item }}
{{else}}
<!-- do something if variable is empty -->
{{/each}}
With
Create a new context with a new variable
{{#with properties.content as content}}
<!-- `content` is now the value of `properties.content` -->
{{ render_markdown(content) }}
{{/with}}
Inline helpers
This is different to inline helpers in handlebars, because Neleto requires the arguments to be wrapped with parentheses:
{{ render_elements(page.elements) }}
or with multiple arguments, separated by commas:
{{ date(page.created_at, "%Y") }}
Built-in helpers
Neletos template language comes with some builtin helpers, which you can use in your templates.
render_elements
This helper renders an array of elements.
{{ render_elements(page.elements) }}
{{ render_elements(children) }}
date
This helper formats dates using the given format.
{{ date(page.created_at, "%Y") }}
To see the available options for the second argument, see Chrono (docs.rs).
Common format specifiers:
| Specifier | Description | Example |
|---|---|---|
%Y | 4-digit year | 2024 |
%y | 2-digit year | 24 |
%m | Month (01-12) | 01 |
%B | Full month name | January |
%b | Abbreviated month name | Jan |
%d | Day (01-31) | 15 |
%H | Hour, 24-hour (00-23) | 14 |
%I | Hour, 12-hour (01-12) | 02 |
%M | Minutes (00-59) | 30 |
%S | Seconds (00-59) | 05 |
%p | AM / PM | PM |
%A | Full weekday name | Monday |
%a | Abbreviated weekday | Mon |
render_markdown
Renders a string of markdown into HTML.
{{ render_markdown(properties.content) }}
sanitize
sanitizes an input string from HTML.
{{ sanitize(properties.html_code) }}
render_structured_data
renders blog post structured data
{{ render_structured_data(relations.post) }}
image_path
renders a path to an image with parameters.
{{ image_path(relation.image, "f_webp") }}
See Image Scaling for a full list of available options (size, format, quality, etc.).
file_path
renders a path to a file without parameters.
{{ file_path(relations.file) }}
render_meta_tag
render meta tag from the page or settings.
{{ render_meta_tag(meta_tag) }}
stringify
stringify any value to json.
{{ stringify(properties) }}
render
render any value with handlebars and the current context.
{{ render(properties.handlebars) }}