-
Notifications
You must be signed in to change notification settings - Fork 0
Home
A Koa view renderer based on the Eta template engine.
Install the latest version of Eta for Koa with npm package manager:
npm install @cedx/koa-eta
For detailed instructions, see the installation guide.
This library provides an eta()
function that you simply invoke by passing the instance
of your Koa application as an argument.
import {eta} from "@cedx/koa-eta";
import Koa from "koa";
// Initialize the application.
const app = new Koa;
eta(app);
This function will add two new methods render()
and renderPdf()
to the request context,
that you can use to render Eta view templates.
// Render the "view.eta" template.
app.use(async ctx => {
return ctx.render("view");
});
For more information, visit the pages dedicated to each of them:
The eta()
function accepts an option object as a second argument.
These options are directly passed to the Eta
constructor.
The most important one is the views
option that let you specify the path of the directory containing your view templates.
import {eta} from "@cedx/koa-eta";
import {join} from "node:path";
// Initialize the template engine.
const directory = join(import.meta.dirname, "path/to/view/folder");
eta(app, {views: directory});
Warning
The views
option should be set to use the template engine.
Otherwise, an EtaFileResolution
error will be raised when rendering file-based templates.
Please refer to the Eta documentation for details of all configuration options.