Handlebars
neleto has its own template engine based on 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).
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") }}
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_builder
render builder items
{{ render_builder(properties.builder) }}
render
render any value with handlebars and the current context.
{{ render(properties.handlebars) }}