2022-08-08 11:56:04 +00:00
|
|
|
|
```meta
|
2022-08-08 18:16:43 +00:00
|
|
|
|
type: plug
|
2022-08-08 11:56:04 +00:00
|
|
|
|
uri: builtin:core
|
|
|
|
|
repo: https://github.com/silverbulletmd/silverbullet
|
|
|
|
|
author: Silver Bullet Authors
|
2022-08-10 07:18:11 +00:00
|
|
|
|
$disableDirectives: true
|
2022-08-08 11:56:04 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
This documentation is still a WIP.
|
|
|
|
|
|
|
|
|
|
## Templating
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
2022-08-08 11:56:04 +00:00
|
|
|
|
The core plug implements a few templating mechanisms.
|
|
|
|
|
|
|
|
|
|
### Page Templates
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
The {[Template: Instantiate Page]} command enables you to create a new page
|
|
|
|
|
based on a page template.
|
|
|
|
|
|
|
|
|
|
Page templates, by default, are looked for in the `template/page/` prefix. So
|
|
|
|
|
creating e.g. a `template/page/Meeting Notes` page will create a “Meeting Notes”
|
|
|
|
|
template. You can override this prefix by setting the `pageTemplatePrefix` in
|
|
|
|
|
`SETTINGS`.
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
Page templates have one “magic” type of page metadata that is used during
|
|
|
|
|
instantiation:
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
- `$name` is used as the default value for a new page based on this template
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
|
|
|
|
In addition, any standard template placeholders are available (see below)
|
|
|
|
|
|
|
|
|
|
For instance:
|
|
|
|
|
|
|
|
|
|
```meta
|
2022-08-09 13:37:47 +00:00
|
|
|
|
$name: "📕 "
|
2022-08-08 11:56:04 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# {{page}}
|
|
|
|
|
As recorded on {{today}}.
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
2022-08-08 11:56:04 +00:00
|
|
|
|
## Introduction
|
|
|
|
|
## Notes
|
|
|
|
|
## Conclusions
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
Will prompt you to pick a page name (defaulting to “📕 “), and then create the
|
|
|
|
|
following page (on 2022-08-08) when you pick “📕 Harry Potter” as a page name:
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
|
|
|
|
# 📕 Harry Potter
|
|
|
|
|
As recorded on 2022-08-08.
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
2022-08-08 11:56:04 +00:00
|
|
|
|
## Introduction
|
|
|
|
|
## Notes
|
|
|
|
|
## Conclusions
|
|
|
|
|
|
|
|
|
|
### Snippets
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
Snippets are similar to page templates, except you insert them into an existing
|
|
|
|
|
page with the `/snippet` slash command. The default prefix is `snippet/` which
|
|
|
|
|
is configurable via the `snippetPrefix` setting in `SETTINGS`.
|
|
|
|
|
|
|
|
|
|
Snippet templates do not support the `$name` page meta, because it doesn’t
|
|
|
|
|
apply.
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
However, snippets do support the special `|^|` placeholder for placing the
|
|
|
|
|
cursor caret after injecting the snippet. If you leave it out, the cursor will
|
|
|
|
|
simply be placed at the end, but if you like to insert the cursor elsewhere,
|
|
|
|
|
that position can be set with the `|^|` placeholder.
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
|
|
|
|
For instance to replicate the `/query` slash command as a snippet:
|
|
|
|
|
|
|
|
|
|
<!-- #query |^| -->
|
|
|
|
|
|
|
|
|
|
<!-- /query -->
|
|
|
|
|
|
|
|
|
|
Which would insert the cursor right after `#query`.
|
|
|
|
|
|
2022-08-10 07:18:11 +00:00
|
|
|
|
### Dynamic template injection
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
|
|
|
|
In addition to using the `/snippet` slash command to insert a template as a
|
|
|
|
|
one-off, it’s also possible to reuse templates that update dynamically (similar
|
|
|
|
|
to [[🔌 Query]]). For this, you use the `#use` and `#use-verbose` directives.
|
2022-08-10 07:18:11 +00:00
|
|
|
|
|
|
|
|
|
In its most basic form:
|
|
|
|
|
|
|
|
|
|
<!-- #use [[template/plug]] -->
|
|
|
|
|
<!-- /use -->
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
Upon load (or when updating materialized queries) the body of this dynamic
|
|
|
|
|
section will be replaced with the content of the referenced template.
|
2022-08-10 07:18:11 +00:00
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
The referenced template will be treated as a Handlebars template (just like when
|
|
|
|
|
using a `render` clause with `#query`).
|
2022-08-10 07:18:11 +00:00
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
Optionally, you can pass any JSON-formatted value as an argument, which will be
|
|
|
|
|
exposed in the template as the top-level value.
|
2022-08-10 07:18:11 +00:00
|
|
|
|
|
|
|
|
|
For example, given the following template:
|
|
|
|
|
|
|
|
|
|
Hello there {{name}} you are {{age}} years old!
|
|
|
|
|
|
|
|
|
|
You can reference and instantiate as follows:
|
|
|
|
|
|
|
|
|
|
<!-- #use [[template/plug]] {"name": "Pete", "age": 50} -->
|
|
|
|
|
<!-- /use -->
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
If a template contains any dynamic sections with directives, these will all be
|
|
|
|
|
removed before injecting the content into the page. This makes things look
|
|
|
|
|
cleaner. If you want to preserve them, use `#use-verbose` instead of `#use`.
|
2022-08-10 07:18:11 +00:00
|
|
|
|
|
2022-08-08 11:56:04 +00:00
|
|
|
|
### Daily Note
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
|
|
|
|
The {[Open Daily Note]} command navigates (or creates) a daily note prefixed
|
|
|
|
|
with a 📅 emoji by default, but this is configurable via the `dailyNotePrefix`
|
|
|
|
|
setting in `SETTINGS`. If you have a page template (see above) named
|
|
|
|
|
`Daily Note` it will use this as a template, otherwise, the page will just be
|
|
|
|
|
empty.
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
|
|
|
|
### Quick Note
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
|
|
|
|
The {[Quick Note]} command will navigate to an empty page named with the current
|
|
|
|
|
date and time prefixed with a 📥 emoji, but this is configurable via the
|
|
|
|
|
`quickNotePrefix` in `SETTINGS`. The use case is to take a quick note outside of
|
|
|
|
|
your current context.
|
2022-08-08 11:56:04 +00:00
|
|
|
|
|
|
|
|
|
### Template placeholders
|
2022-10-12 09:47:13 +00:00
|
|
|
|
|
2022-08-08 11:56:04 +00:00
|
|
|
|
Currently supported (hardcoded in the code):
|
|
|
|
|
|
2022-10-12 09:47:13 +00:00
|
|
|
|
- `{{today}}`: Today’s date in the usual YYYY-MM-DD format
|
|
|
|
|
- `{{tomorrow}}`: Tomorrow’s date in the usual YYY-MM-DD format
|
|
|
|
|
- `{{yesterday}}`: Yesterday’s date in the usual YYY-MM-DD format
|
|
|
|
|
- `{{lastWeek}}`: Current date - 7 days
|
|
|
|
|
- `{{page}}`: The name of the current page
|