Quik Framework :: Templates
- Codename: Berlin
- Version: 0.2.0-beta.76
- License: Check license here
Offers template rendering with helpers. It depends on the HTTP module and registers default Handlebars helpers during setup.
Installation
npm install @quik/templates
Usage
Load templates and render:
import { TemplatesStore, QTemplate } from '@quik/templates';
await TemplatesStore.load('core', './templates');
class WelcomeTemplate extends QTemplate<{ name: string }> {
constructor(name: string) {
super('core.welcome', { name });
}
}
const output = new WelcomeTemplate('Quik').render();
TemplatesStore.load() loads templates into memory. If template files change on disk, call TemplatesStore.reload() to re-read templates, or clear() and load() to reset the store.
Configuration
Optional config flags:
templates.throwOnMissing: throw when a template key is missing (default:false).templates.disableCache: re-read templates from disk on everyget()(default:false).
Reloading & Partials
Template and partial names are stored as lowercase module.filename keys (for example core.email.welcome).
Partials follow the same naming convention and must be loaded through PartialsStore.load().
When hot-reloading in development, clear and reload partials before rendering templates so that new partial
contents are registered with Handlebars.
API Highlights
QTemplatebase class for rendering templates.TemplatesStore.load(),.get(), and.clear()for template discovery.HelpersStoreandPartialsStorefor Handlebars helpers/partials (usePartialsStore.clear()before reloading).
Testing & Coverage
See the root instructions for details on running pnpm run test:coverage and accessing coverage artifacts.
API Reference
Generated API documentation is available in the templates API section.