-
Notifications
You must be signed in to change notification settings - Fork 63
Understanding Templates
Templates used by Obsidian Web are written in the Handlebars template language -- see their guide to get an understanding of how Handlebars templates work.
A very simple content template might look like this:
## {{date}}
{{#if page.selectedText}}
{{quote page.selectedText}}
{{/if}}
This template will be merged with context data from your page (see below). For example, imagine it's November 12th, 2023 and you've selected this part of the page:
When rendered, this template will generate this output:
## 2023-11-12 14:14:24
> This is an unofficial Chrome extension for Obsidian that lets you send content from the web to your notes in Obsidian.
>
> Do you find yourself on a webpage somewhere and want to add it to your notes so you can remember it later? You can use Obsidian Web for sending any web content from Chrome to your Obsidian Notes easily by just clicking on a button in your toolbar.
When configuring a template, your template will be provided some context from the page you're currently viewing including:
Name | Description | Notes |
---|---|---|
page.url |
URL of the page | |
page.title |
Title of the page | From HTML <title>
|
page.selectedText |
Text currently selected in the window | Processed with Readability |
page.content |
Full content of the loaded window | Processed with Readability |
article.title |
Article title (if available) | Provided by Readability |
article.length |
Length of the article in characters (if available) | Provided by Readability |
article.excerpt |
Article description or short excerpt from the content (if available) | Provided by Readability |
article.byline |
Author metadata (if available) | Provided by Readability |
article.dir |
Content direction (if available) | Provided by Readability |
article.siteName |
Name of the site (if available) | Provided by Readability |
Your template has access to all built-in helpers provided by Handlebars, but this plugin also provides you a handful of other useful helpers including:
Name | Description | Notes |
---|---|---|
quote |
Quotes the provided variable | Inserts a > before each line of the variable so that it will be rendered as quoted text |
date FORMAT |
Render the current date using the provided variable FORMAT
|
See date-fns ' format documentation for format options. If FORMAT is unspecified, uses yyyy-MM-dd HH:mm:ss as a format. |
filename NAME |
Strip all filename-unsafe characters from variable NAME
|
|
json DATA |
Format variable DATA as a JSON string |
|
uuid |
Return a randomly-generated UUID |
In the above documentation, fields in all-caps like FORMAT
, NAME
, and DATA
are assumed to be context variables -- if you want to provide data that is not stored in a context variable to a helper, you will need to use quotes. For example, if you would like to use the date
helper described above to output the current date, but you would like to use the format EEEE, MMMM do
instead of the default, you would need to enter {{ date "EEEE, MMMM do"}}
in your template.