notesy::templates
Templates are notes to put in a note, or start one from: the notes in the
templates folder (Settings, Daily notes, says which; Templates unless it
says), put in with Insert template and New note from template in
the palette, or from the sidebar (right-click a template, a folder, a New
note button, or the room around the notes), and the daily note's template too. What's written in them to
fill in is filled in as they're used. A plugin can add functions of its
own for them to call, which takes the templates permission.
#What a template can say
Obsidian's way and Templater's are both read, in any template.
| Written | Filled in with |
|---|---|
{{date}}, {{date:dddd, MMMM D}} |
the day it's for (today, or a daily note's), in a format |
{{time}}, {{time:HH:mm:ss}} |
now |
{{yesterday}}, {{tomorrow}} |
the days around it, formats as date's |
{{title}} |
the note's name |
{{folder}}, {{path}} |
its folder in the vault, and its path |
{{selection}}, {{clipboard}} |
what was selected where it's put in, and what's copied |
{{cursor}} |
nothing: where the caret goes once it's in |
| Written | Filled in with |
|---|---|
<% tp.date.now(format, offset) %> |
the day, moved by offset: a number of days (7, -1), or "P1W", "P1M", "P1Y" |
<% tp.date.tomorrow(format) %>, <% tp.date.yesterday(format) %> |
the days around it |
<% tp.date.weekday(format, n) %> |
this week's day n, Sunday its first (0) |
<% tp.file.title %> |
the note's name |
<% tp.file.folder() %>, <% tp.file.folder(true) %> |
its folder's name, or its path in the vault |
<% tp.file.path() %> |
its path in the vault |
<% tp.file.creation_date(format) %> |
when it's made |
<% tp.file.selection() %>, <% tp.system.clipboard() %> |
what was selected, and what's copied |
<% tp.file.cursor() %> |
nothing: where the caret goes once it's in |
<% tp.system.prompt(question, default) %> |
what the user types |
<% tp.system.suggester(labels, values, false, question) %> |
the value beside the one of labels the user picks |
Formats are Obsidian's (moment.js tokens: YYYY, MM, DD, dddd,
HH:mm, [literal text]), or strftime's when they have a %. Every
question a template asks (its prompts and suggesters) is asked at once, in
one dialog, before it's put in; Cancel puts nothing in. <%- and -%>
take the line break before or after the tag with them, and <%_ and _%>
all the space.
What a function is given is plain values: text in quotes, numbers, true
and false, and lists of them in [ ]. Nothing in a template is run:
Templater's <%* … %> stays as it's written, as does anything notesy
doesn't know, so a template shared by someone can't do anything but fill
itself in.
A template with template-for: <folder> in its front matter starts every
new note made in that folder (template-for: Meetings); that line isn't
put in the note. Right-click a template and pick Use for new notes in…
to set it (a folder has one template: the one it had stops). A note made
from a template says which in its template property
(template: "[[Meeting]]").
#Functions of a plugin's own
rustuse notesy::{net, templates};
pub fn ready() {
// <% tp.weather.today("Bangor") %>
templates::add("today", |call| {
let town = call.args.get(0).unwrap_or("Cardiff");
net::fetch(`https://wttr.in/${net::encode(town)}?format=3`, |result| {
let text = match result {
Ok(response) => response.text,
Err(e) => "no forecast",
};
templates::answer(call.id, text);
});
});
// <% tp.weather.greeting() %>: answered at once.
templates::add("greeting", |call| `Bore da from ${call.note.title}`);
}
| Function | What it does |
|---|---|
templates::add(name, handler) |
A function templates call as tp.<plugin>.<name>(…). <plugin> is the last part of the plugin's id, - as _ (example.weather is tp.weather). handler(call) gets #{ args, note, id }: what it was given (a list), the note (#{ title, path, folder }) and the call's id. It returns what to put in, text or a number, or nothing, to answer later with templates::answer. Adding it again changes it. |
templates::answer(id, text) |
What to put in for call id, from a function that answers once it knows. |
A template waits 4 seconds for its plugins' functions (while the user
answers its questions, too); a call with no answer by then, or to a
function that isn't there or fails, stays in the note as it was written.
Two plugins can't both be tp.weather: the second's functions aren't added,
and its log says so.
Every page
- Overview
- plugin.toml: Every field of plugin.toml
- Permissions: What a plugin can ask for, when notesy asks, and what changes it
- Scripts: How a script runs: its lifecycle, events, limits and errors
- Packing and installing: Making, checking, signing, packing and installing
- notesy::log: Lines for its log on the Plugins page
- notesy::events: Hearing what happens, and every event
- notesy::commands: Adding commands, and running notesy's
- notesy::store: Keeping its own data
- notesy::settings: Reading its settings
- notesy::secrets: Keys and tokens, in the system keychain
- notesy::notes: Reading and changing the vault's notes
- notesy::editor: The note in front
- notesy::templates: What templates fill in, and functions of its own for them
- notesy::files: A folder of its own
- notesy::links: Opening pages in the browser, naming links after their pages
- notesy::clipboard: Copying and pasting
- notesy::view: What panels, tabs and sections show
- notesy::panels and notesy::views: Adding side panels and tabs
- notesy::sections: Sidebar sections
- notesy::menus: Items in notesy's right-click menus
- notesy::status: Status bar items
- notesy::notices: Notices
- notesy::dialogs: Asking in a dialog, notesy's kinds or its own
- notesy::wizards: Pages one after another, like a setup
- notesy::cards: Its part of the tree's hover cards
- notesy::boards: Boards' cards and arrows, and kinds of card of its own
- notesy::blocks: Drawing its fenced blocks
- notesy::icons: Drawing its own icons
- notesy::net: Requests to the sites it names
- notesy::accounts: Signing in to a service
- notesy::json: Reading and writing JSON
- notesy::toml: Reading and writing TOML
- notesy::yaml: Reading and writing YAML, and a note's front matter
- notesy::time: Now, written in the user's time zone, dates read, how long ago
- notesy::math: Trigonometry and the like, for drawing
- Names: Icon, Color, Tone, Side, Method, Command, Menu, Sidebar, Event: Notesy's names as enums
- notesy::preview: Its own screens for notesy preview
- notesy::perf: Timing its own work
- notesy::tex: Math macros for every note's formulas