String Interpolation
Overview
You can use standard JavaScript string interpolation within np.Templating
tags.
- Plugin Code
- Template
- Output
For example, using the following in your plugin code, you can provide the referenced fname
, mname
, and lname
variables
export async function templatingInterpolation(): Promise<void> {
try {
const data = { fname: 'Mike', mname: 'Joseph', lname: 'Erickson' }
const result = await NPTemplating.renderTemplate('Test (Interpolation)', data)
Editor.insertTextAtCursor(result)
} catch (error) {
showError(error)
}
}
In your template, you can reference these variables
INTERPOLATION
Make sure you use the standard interpolation ticks (`) around the text block which contains desired variables
Full Name: <%- `${fname} ${mname} ${lname}` %>
When your template is rendered, it will appear as
Full Name: Mike Joseph Erickson