2024-01-20 18:16:07 +00:00
Live Templates are a type of [[Blocks|block]] that render [[Templates]] inline in a page.
2023-10-03 12:16:33 +00:00
2024-01-20 18:16:07 +00:00
Template blocks are specified using [[Markdown]]‘ s fenced code block notation using `template` as a language. The body of the block specifies the template to use, as well as any arguments to pass to it.
2023-10-03 12:16:33 +00:00
2023-12-21 17:37:50 +00:00
Generally you’ d use it in one of two ways, either using a `page` [[Templates|template]] reference, or an inline `template` :
2023-10-03 12:16:33 +00:00
Here’ s an example using `page` :
```template
2024-01-20 18:16:07 +00:00
page: "[[internal-template/today]]"
2023-10-03 12:16:33 +00:00
```
2023-12-21 17:37:50 +00:00
And here’ s an example using `template` :
2023-10-03 12:16:33 +00:00
```template
template: |
Today is {{today}}!
```
2024-01-08 16:08:26 +00:00
To pass a literal value to the template, you can specify the optional `value` attribute:
2023-10-03 12:16:33 +00:00
```template
template: |
Hello, {{name}}! Today is _{{today}}_
value:
name: Pete
```
2024-01-08 16:08:26 +00:00
You can also pass in the result of a [[Live Queries|query]] as a value by setting the `query` attribute:
```template
2024-01-20 18:16:07 +00:00
query: |
tag where parent = "page" select name
2024-01-08 16:08:26 +00:00
template: |
{{#each .}}
* #{{name}}
{{/each}}
```
2023-12-21 17:37:50 +00:00
If you just want to render the raw markdown without handling it as a handlebars template, set `raw` to true:
2023-10-03 12:16:33 +00:00
```template
template: |
This is not going to be {{processed}} by Handlebars
raw: true
```