Files
plainleaf/website/API/template.md
T
Marek S. ŁukasiewiczandGitHub f2f4937854 Utility function to handle empty query results and templates (#1386)
* Add global Lua function 'some'

Moved documentation for 'each' function to non-standard section.

* Revert "Add optional argument to template.each for empty collection output (#1359)"

This reverts commit b73dadec67.

* Reimplement #1359 using 'some' function
2025-05-12 07:33:49 +02:00

634 B

Template functions that use the API/template#template.new(template) function.

template.new(template)

Returns a template function that can be used to render a template. Conventionally, a template string is put between [==[ and ]==] as string delimiters.

Example:

examples = examples or {}

examples.sayHello = template.new[==[Hello ${name}!]==]

And its use: ${examples.sayHello {name="Pete"}}

template.each(collection, template)

Iterates over a collection and renders a template for each item.

Example:

${template.each(queryfrom index.tag "page" limit 3, template.new[==[ * ${name} ]==])}