Skip to content

renderPartialFromFile / renderPartialFromSource

Render a named partial from a template file or source string.

renderPartialFromFile

Render a named partial from a template file.

renderPartialFromFile(fileName, partialName, contextObj, options)

Parameters

| Parameter | Type | Description |

|-----------|------|-------------|

| fileName | string | Template file name (without extension) |

| partialName | string | Name of the partial to render |

| contextObj | object | Variables to inject |

| options | object | Options including views directories |

Example

const { renderPartialFromFile } = require('miki-template');



const html = renderPartialFromFile('home', 'card', { title: 'Hello' }, { views: './views' });
import { renderPartialFromFile } from 'miki-template';



const html = renderPartialFromFile('home', 'card', { title: 'Hello' }, { views: './views' });

renderPartialFromSource

Render a named partial from a template source string.

renderPartialFromSource(fileContent, partialName, contextObj, options, filePath?)

Parameters

| Parameter | Type | Description |

|-----------|------|-------------|

| fileContent | string | Template source string |

| partialName | string | Name of the partial to render |

| contextObj | object | Variables to inject |

| options | object | Options |

| filePath | string? | Optional file path for error messages |

Example

const { renderPartialFromSource } = require('miki-template');



const source = `{% partialdef card %}<div>{{ title }}</div>{% endpartialdef %}`;

const html = renderPartialFromSource(source, 'card', { title: 'Hello' });
import { renderPartialFromSource } from 'miki-template';



const source = `{% partialdef card %}<div>{{ title }}</div>{% endpartialdef %}`;

const html = renderPartialFromSource(source, 'card', { title: 'Hello' });