Skip to main content

Example 2: Custom Variables

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


For example, if you have an arbitrary plugin method which would output a variable, it would be constructed as follows
import NPTemplating from 'NPTemplating'

export async function templatingHelloWorld(): Promise<void> {
try {
const templateData = {
data: {
name: 'Mike'
}
}
const result = await NPTemplating.renderTemplate('Template (Variable)', templateData)

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