Skip to main content

Example 1: Hello World

In this example, we will expose the NPTemplating module and use the renderTemplate method

Using NPTemplating module

The NPTemplating module contains suite of methods which can be used for various operations.

renderTemplate(templateName: string, templateData?: object)

The renderTemplate method will render using the supplied templateName and templateData arguments

templateName: string

Desired template name, located in NotePlan templates folder

templateData?: object

Template data object, which will contain any custom template variables or methods

templateData has two objects which are used to supply data and methods

  • data - Any data (variables) which are referenced in your template
  • methods - Any method that is referenced in your template
const templateData = {
data: {},
methods: {}
}

For example, if you have an arbitrary plugin method called showHelloWorld it could look something like the following

import NPTemplating from 'NPTemplating'

export async function showHelloWorld(): Promise<void> {
try {
const result = await NPTemplating.renderTemplate('Template (Hello World)')

Editor.insertTextAtCursor(result)
} catch (error) {
console.log('showHelloWorld', error)
}
}