render()
Render a template string or file partial.
Signature
render(templateStr, contextObj = {}, options = {})
Parameters
| Parameter | Type | Description |
|-----------|------|-------------|
| templateStr | string | Template string or file path with #partial suffix |
| contextObj | object | Variables to inject into the template |
| options | object | Options including views directories and custom settings |
Returns
string — The rendered HTML.
Examples
Render a template string
Render a partial from file
Render with options
const { render } = require('miki-template');
const html = render(template, context, {
views: ['./views', './app/templates'],
staticUrl: '/static',
urlHelper: (name, ...args) => '/' + name + '/' + args.join('/')
});
import { render } from 'miki-template';
const html = render(template, context, {
views: ['./views', './app/templates'],
staticUrl: '/static',
urlHelper: (name, ...args) => '/' + name + '/' + args.join('/')
});