silverbullet/website/API/template.md

23 lines
635 B
Markdown
Raw Normal View History

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:
```space-lua
examples = examples or {}
examples.say_hello = template.new[==[Hello ${name}!]==]
```
And its use: ${examples.say_hello {name="Pete"}}
2025-01-15 03:26:47 +08:00
## template.each(collection, template)
Iterates over a collection and renders a template for each item.
Example:
${template.each(query[[from index.tag "page" limit 3]], template.new[==[
2025-01-15 03:26:47 +08:00
* ${name}
]==])}