Render template (adapted from doT.js)
The data made available to the template is always on the data key, e.g.: renderer({ myVal: "xx" }) ... will be accessible on <%= data.myVal %>
data
renderer({ myVal: "xx" })
<%= data.myVal %>
The default delimiters are customised to work without conflicts with Blade and Twig:
<% %> for evaluation<%= %> for interpolation<%? %> for conditionals<%~ %> for array iteration<%# %> for compile-time evaluation/includes and partials<%## #%> for compile-time definesUnsupported:<%! %> for interpolation with encoding Copy
<% %> for evaluation<%= %> for interpolation<%? %> for conditionals<%~ %> for array iteration<%# %> for compile-time evaluation/includes and partials<%## #%> for compile-time definesUnsupported:<%! %> for interpolation with encoding
Optional
import { render } from "...";const data = { name: "XYZ" };const tpl = `Hello <%= data.name %>`;const renderer = render(tpl);console.log(renderer(data)); // outputs 'Hello XYZ' Copy
import { render } from "...";const data = { name: "XYZ" };const tpl = `Hello <%= data.name %>`;const renderer = render(tpl);console.log(renderer(data)); // outputs 'Hello XYZ'
olado/doT by Laura Doktorova
https://olado.github.io/doT/index.html
Render template (adapted from doT.js)
The data made available to the template is always on the
datakey, e.g.:renderer({ myVal: "xx" })... will be accessible on<%= data.myVal %>The default delimiters are customised to work without conflicts with Blade and Twig: