Renamed #inject to #use
parent
6c7bb825a8
commit
47faea2289
|
@ -195,21 +195,21 @@ functions:
|
|||
insertInjectTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: inject
|
||||
description: Inject template
|
||||
name: use
|
||||
description: Use a template
|
||||
value: |
|
||||
<!-- #inject [[|^|]] {} -->
|
||||
<!-- #use [[|^|]] {} -->
|
||||
|
||||
<!-- /inject -->
|
||||
<!-- /use -->
|
||||
insertInjectCleanTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
name: inject-clean
|
||||
description: Inject template clean
|
||||
name: use-verbose
|
||||
description: Use a template (verbose mode)
|
||||
value: |
|
||||
<!-- #inject-clean [[|^|]] {} -->
|
||||
<!-- #use-verbose [[|^|]] {} -->
|
||||
|
||||
<!-- /inject-clean -->
|
||||
<!-- /use-verbose -->
|
||||
insertHRTemplate:
|
||||
path: "./template.ts:insertTemplateText"
|
||||
slashCommand:
|
||||
|
|
|
@ -35,7 +35,7 @@ export async function updateMaterializedQueriesCommand() {
|
|||
}
|
||||
|
||||
export const templateInstRegex =
|
||||
/(<!--\s*#(inject|inject-clean|include)\s+\[\[([^\]]+)\]\](.*?)-->)(.+?)(<!--\s*\/\2\s*-->)/gs;
|
||||
/(<!--\s*#(use|use-verbose|include)\s+\[\[([^\]]+)\]\](.*?)-->)(.+?)(<!--\s*\/\2\s*-->)/gs;
|
||||
|
||||
async function updateTemplateInstantiations(
|
||||
text: string,
|
||||
|
@ -68,7 +68,7 @@ async function updateTemplateInstantiations(
|
|||
}
|
||||
let newBody = templateText;
|
||||
// if it's a template injection (not a literal "include")
|
||||
if (type == "inject" || type === "inject-clean") {
|
||||
if (type === "use" || type === "use-verbose") {
|
||||
let tree = await parseMarkdown(templateText);
|
||||
extractMeta(tree, ["$disableDirectives"]);
|
||||
templateText = renderToText(tree);
|
||||
|
@ -88,7 +88,7 @@ async function cleanTemplateInstantiations(text: string): Promise<string> {
|
|||
text,
|
||||
templateInstRegex,
|
||||
async (fullMatch, startInst, type, template, args, body, endInst) => {
|
||||
if (type === "inject-clean") {
|
||||
if (type === "use") {
|
||||
body = body.replaceAll(
|
||||
queryRegex,
|
||||
(
|
||||
|
@ -142,7 +142,7 @@ export async function updateMaterializedQueriesOnPage(
|
|||
|
||||
let parsedQuery = parseQuery(replaceTemplateVars(query, pageName));
|
||||
|
||||
console.log("Parsed query", parsedQuery);
|
||||
// console.log("Parsed query", parsedQuery);
|
||||
// Let's dispatch an event and see what happens
|
||||
let results = await dispatch(
|
||||
`query:${parsedQuery.table}`,
|
||||
|
|
|
@ -6,10 +6,10 @@ An attempt at documenting of the changes/new features introduced in each (pre) r
|
|||
* For the `Template: Instantiate Page` command, the page meta value `$name` is now used to configure the page name (was `name` before). Also if `$name` is the only page meta defined, it will remove the page meta entirely when instantiating.
|
||||
* You can now configure a daily note prefix with `dailyNotePrefix` in `SETTINGS` and create a template for your daily note under `template/page/Daily Note` (configurable via the `dailyNoteTemplate` setting).
|
||||
* You can now a quick note prefix with `quickNotePrefix` in `SETTINGS`.
|
||||
* Directives (e.g. `#query`, `#import`, `#inject`) changes:
|
||||
* Renamed `#template` directive to `#inject`
|
||||
* New `#inject-clean` directive will clean all the embedded queries and templates in its scope
|
||||
* All directives now use the page reference syntax `[[page name]]` instead of `"page name"`, this includes `#inject` and `#inject-clean` as well as `#import`.
|
||||
* Directives (e.g. `#query`, `#import`, `#use`) changes:
|
||||
* Renamed `#template` directive to `#use-verbose`
|
||||
* New `#use` directive will clean all the embedded queries and templates in its scope
|
||||
* All directives now use the page reference syntax `[[page name]]` instead of `"page name"`, this includes `#use` and `#use-verbose` as well as `#import`.
|
||||
* The `link` query provider now also returns the `pos` of a link (in addition to the `page`)
|
||||
* New `$disableDirectives` page meta data attribute can be used to disable directives processing in a page (useful for templates)
|
||||
* Added a new `/hr` slash command to insert a horizontal rule (`---`) useful for mobile devices (where these are harder to type)
|
||||
|
|
|
@ -3,6 +3,7 @@ type: plug
|
|||
uri: builtin:core
|
||||
repo: https://github.com/silverbulletmd/silverbullet
|
||||
author: Silver Bullet Authors
|
||||
$disableDirectives: true
|
||||
```
|
||||
|
||||
This documentation is still a WIP.
|
||||
|
@ -58,6 +59,31 @@ For instance to replicate the `/query` slash command as a snippet:
|
|||
|
||||
Which would insert the cursor right after `#query`.
|
||||
|
||||
### Dynamic template injection
|
||||
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.
|
||||
|
||||
In its most basic form:
|
||||
|
||||
<!-- #use [[template/plug]] -->
|
||||
<!-- /use -->
|
||||
|
||||
Upon load (or when updating materialized queries) the body of this dynamic section will be replaced with the content of the referenced template.
|
||||
|
||||
The referenced template will be treated as a Handlebars template (just like when using a `render` clause with `#query`).
|
||||
|
||||
Optionally, you can pass any JSON-formatted value as an argument, which will be exposed in the template as the top-level value.
|
||||
|
||||
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 -->
|
||||
|
||||
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`.
|
||||
|
||||
### Daily Note
|
||||
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.
|
||||
|
||||
|
|
Loading…
Reference in New Issue