Skip to main content

Template Anatomy

np.Templating templates use a format called Frontmatter, that is commonly found in blogging platforms which utilizes templates to render dynamic content, and is a great fit for the way NotePlan integrates normal note taking features, but infuses a robust calendaring system.

Template Configuration

There are two parts to a NotePlan template. Depending on the type of template you are creating, there will be at least two attributes, and template body.

The template must start with three dashes --- followed by template attributes, then three more dashes --- and then the template body, which will be the content that will be rendered when invoking any of the np.Templating commands.

All templates must be placed in the "Templates" folder, which can be found in NotePlan Sidebar, located in the "Smart Folders" section.

NotePlan Event

Template Sections

There are two sections in a NotePlan template, template attributes and template body.

Template attributes

attributes - The attribute section is between opening --- and closing --- tags, and contains all configuration key/value pairs, separated by colon : character.

REQUIRED ATTRIBUTES

All templates must have at least two required attributes title and type.

AttributeDescription
titleThe title attribute is the name of template, and will appear in the Templates folder
typeThe type attribute determine the type of template, and will control where it is accessible from.

The following are the the list of possible type values:

TypeDescription
empty-noteis a generic note and can be used for anything that will be processed by the various np.Templating commands such as np:new, np:insert, np:append, np:invoke
meeting-notetemplates will be available when selecting any of the locations associated with meetings (those displayed in NotePlan calendar)
quick-notetemplates are accessible when invoking the np.Templating quick note command np:qtn
templateUsed with the <%- include(/** **/) %> tag, used when creating including templates within other templates
IDENTIFY TEMPLATE FRONTMATTER

NotePlan will display the frontmatter attributes in an alternate tint color NotePlan Event

Template body

body - The remainder of template, placed after the second delimiter line--- is the template content and will be use when template is rendered.

Example

---
title: Template title
type: empty-note
---
Everything below the second `---` will be template content

--
created: <%- date.now('dddd MMMM Do, YYYY HH:mm A') %>
--

< -- [[<%- date.yesterday('YYYY-MM-DD') %>]] | [[<%- date.tomorrow('YYYY-MM-DD') %>]] -- >

And the remainder of the template will be display here ...

Template Attribute Processing

When a template is processed, the first portion will be template attributes, where you can use static text, or other np.Templating commands to provide the setup, before moving onto rendering the template body.

REENTRANCE SUPPORT

When np.Templating is rendering a template, it processes in a top-down fashion and uses a process know as "reentrance", which provides the ability to reference any previous attribute values as the basis for the current attribute.

Template Body Processing

After the attributes have been processed, the next pass will process the template body. You can use any of the supported np.Templating modules, or reference any attribute from the processed template attributes.

Example

The following example will perform the following

  • startDate will be supplied based on prompt for user to enter start date value

  • endDate will use the startDate value from previous attribute, and subtract 7 days, using add method in Date Module

  • formattedDate demonstrates how to create custom formatting, using startDate and endDate attributes

  • In the template body, you will see how we can use any of these attributes to produce further formatting, etc.

---
startDate: <%- prompt('startDate','Enter Date') %>
endDate: <%- date.add(startDate, 7) %>
formattedDate: <%- startDate %> to <%- endDate %>
type: empty-note
---
**Frontmatter Processing**
x
In this example, the following occurs
- The `startDate` attribute is supplied from user input (prompt)
- The `endDate` attribute is derived by the *DateModule* `add` method, adding 7 days to whatever the user entered
- And finally, the full date is displayed below

#### Date Range
**Start Date:** `<%- startDate %>` *value entered from prompt*
**End Date:** `<%- endDate %>` *calculated adding 7 days to `startDate`*
**Formatted Date:** `<%- formattedDate %>` *calculated from `startDate` and `endDate`*

## Template Body Processing
In this example, the following occurs
- Create reminder value using `startDate` and `subtract` method

**Reminder:** `<%- date.subtract(startDate, 7) %>`