72 lines
3.3 KiB
Markdown
72 lines
3.3 KiB
Markdown
---
|
||
description: A template used to pre-populate new pages.
|
||
tags: glossary
|
||
references:
|
||
- libraries/Library/Std/Infrastructure/Page Templates.md
|
||
- libraries/Library/Std/Page Templates/Page Template.md
|
||
---
|
||
|
||
Page templates can be used to automate or simplify the creation of pages based on a template.
|
||
|
||
# Creating a page template
|
||
1. Run the `Page: From Template` command
|
||
2. Select “Page Template”
|
||
3. Pick a name, the last component of the page name will be used as the template name.
|
||
|
||
## Cursor placement
|
||
In the template’s body text, you can optionally use `|^|` as a placeholder for where the cursor should be after creating the page.
|
||
|
||
## Configuration
|
||
Optional keys you can set in the page’s frontmatter:
|
||
|
||
* `suggestedName`: the proposed name for the new page, can use embedded Lua expressions, like `Daily/${date.today()}`.
|
||
* `confirmName`: Confirm the suggested page name before creating it (defaults to `true`).
|
||
* `openIfExists`: If a page with the `suggestedName` already exists, open it rather than attempting to create it anew.
|
||
* `command`: expose the page template as a command with this name.
|
||
* `key`: Bind the snippet to a keyboard shortcut (note: this requires to _also_ specify the `command` configuration).
|
||
* `mac`: Bind the snippet to a Mac-specific keyboard shortcut.
|
||
* `frontmatter`: Frontmatter to set in the resulting page. Use a YAML literal block scalar
|
||
(`frontmatter: |`) so that the value is passed as a string and `${...}` Lua interpolation
|
||
works. A nested YAML mapping is also accepted (and serialized verbatim), but interpolation
|
||
will be skipped in that case.
|
||
* `priority`: Similar to how space lua scripts are loaded, this controls the order in which page template _commands_ are
|
||
created (see "overriding page templates" below)
|
||
|
||
## Example: Daily note
|
||
The following creates a page template that can be run using the `Journal: Daily Note` command, it automatically creates `Daily/today’s date` if it does not already exist with a bulleted list, putting the cursor at the first bullet. If the page already exists, it navigates there.
|
||
|
||
~~~
|
||
---
|
||
command: "Journal: Daily Note"
|
||
suggestedName: "Daily/${date.today()}"
|
||
confirmName: false
|
||
openIfExists: true
|
||
tags: meta/template/page
|
||
---
|
||
* |^|
|
||
~~~
|
||
|
||
# Currently active page templates
|
||
${query[[
|
||
from p = index.pages("meta/template/page")
|
||
select templates.fullPageItem(p)
|
||
]]}
|
||
|
||
# Instantiating page templates
|
||
You can create a page based on a page template via the ${widgets.commandButton("Page: From Template")} command, or via the command name that you defined in your template’s frontmatter.
|
||
|
||
# Overriding page templates
|
||
If you would like to override an existing page template (for instance the Quick Note) template with your own, you can take advantage of the load order determined by the `priority` frontmatter. Built in page templates will have a priority set that is higher than the default. Therefore, their commands and keybindings will be set early. Therefore, by simply defining your own version of the page template _with the same command name_ will let that version override the versions that are built in.
|
||
|
||
## Example: overriding the Quick Note template
|
||
~~~
|
||
---
|
||
command: Quick Note
|
||
key: "Ctrl-q q"
|
||
suggestedName: "Quick notes/${os.date('%Y-%m-%d/%H-%M-%S')}"
|
||
confirmName: false
|
||
tags: meta/template/page
|
||
---
|
||
This is my quick note version
|
||
~~~
|