Skip to content
Cédric Belin edited this page Nov 9, 2024 · 8 revisions

A Koa view renderer based on the Eta template engine.

Quick start

Install the latest version of Eta for Koa with npm package manager:

npm install @cedx/koa-eta

For detailed instructions, see the installation guide.

Usage

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(ctx => ctx.render("view"));

For more information, visit the pages dedicated to each of them:

Options

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});

Please refer to the Eta documentation for details of all configuration options.

Clone this wiki locally