Koa¶
Use miki-template with Koa by attaching an async render helper to the context.
Setup¶
const Koa = require('koa');
const path = require('path');
const miki = require('miki-template');
const app = new Koa();
app.context.render = async function (view, locals = {}) {
const html = await miki.asyncRender(view, locals, {
views: path.resolve('./views')
});
this.type = 'text/html';
this.body = html;
};
app.use(async (ctx) => {
await ctx.render('index', { user: ctx.state.user });
});
app.listen(3000);
import { Koa } from 'koa';
import miki from 'miki-template';
import path from 'node:path';
const app = new Koa();
app.context.render = async function (view, locals = {}) {
const html = await miki.asyncRender(view, locals, {
views: path.resolve('./views')
});
this.type = 'text/html';
this.body = html;
};
app.use(async (ctx) => {
await ctx.render('index', { user: ctx.state.user });
});
export default app;
Partial Rendering¶
Next Steps¶
- Integrations Overview
- [API Reference: asyncRender param($m) $m.Value -replace '([a-z][a-z0-9-]+).md , '../.md' -replace '([a-z][a-z0-9-]+) , '../.md'