silverbullet/website/Live Templates.md

49 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2024-08-15 22:39:17 +08:00
#level/intermediate
2024-02-24 22:51:55 +08:00
Live Templates are a type of [[Blocks|block]] that render [[Templates]] written in [[Template Language]] inline in a page.
There are two variants of Live Templates:
* `template`: where the template is specified inline in a code block.
* `include`: where an external page (template) is _included_ and rendered.
2024-02-24 22:51:55 +08:00
Template blocks are specified using [[Markdown]]s fenced code block notation using either `template` or `include` as its language. They can also be [[Live Queries#Baking|baked]].
# Template
To specify a template to render inline, you can use the `template` block. The body is written in [[Template Language]].
```template
Today is {{today}}
```
# Include
> **warning** Deprecated, use templates instead
> Include template are primarily here to be a drop-in replacement for the old style template blocks, see below for a suggestion how to use those instead.
A `template` block is configured using [[YAML]] in its body. The following attributes are supported:
* `page`: the page to use as a template
* `value`: an (optional) value to pass to the template
* `raw`: a page reference to include in the page without processing it as a template.
Heres an example using `page`:
```include
page: "[[internal-template/today]]"
```
If you want to include another _page_ (not necessarily a template). unprocessed (so without replacing template placeholders), you can use `raw`:
```include
raw: "[[internal/test page]]"
```
## Recommended alternative
Instead of using the `include` block we recommend you use a `{{template([[template]])}}` directive in a `template` instead as it is more flexible and more natural.
Look for yourself:
```template
{{template([[internal-template/today]])}}
```