Skip to main content

Example 3: Custom Method

In this example, we will expand second example, adding a custom method which is exposed through the templateData argument on the renderTemplate method


For example, if you have an arbitrary plugin method called `sayHello` it could look something like the following
import NPTemplating from 'NPTemplating'

export async function templatingHelloWorld(): Promise<void> {
try {
const templateData = {
methods: {
sayHello: (name: string = '') => {
return `Hello ${name}`
}
}
}
const result = await NPTemplating.renderTemplate('Template (Say Hello)', templateData)

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