EJS
@gaman/ejs is the official middleware for integrating EJS (Embedded JavaScript Templates) as a view engine in the GamanJS framework.
With this, you can render .ejs template files (or other extensions) directly from the controller/handler using the built-in view system of GamanJS.
Install
Section titled “Install”npm install @gaman/ejs ejspnpm install @gaman/ejs ejsyarn install @gaman/ejs ejsbun install @gaman/ejs ejsHow to Use
Section titled “How to Use”Register ejs
Section titled “Register ejs”Add the EJS middleware to your application:
import { ejs } from "@gaman/ejs";
defineBootstrap((app) => { app.mount( ejs({ viewPath: "src/views", // template folder }) );});Creating Template
Section titled “Creating Template”Create the file src/views/index.ejs
<!DOCTYPE html><html> <head> <title><%= title %></title> </head> <body> <h1>Hello, <%= name %>!</h1> </body></html>Render from Route
Section titled “Render from Route”In the route handler, use Res.render():
route.get("/", (ctx) => { return Res.render("index", { title: "My First EJS Page", name: "GamanJS 🚀" });});Config Options
Section titled “Config Options”| Name | Type | Default | Description |
|-------------|-------------------------------------------------------------|---------------|-----------|
| viewPath | string | "src/views" | Root directory where EJS templates are located. |
Please read the more detailed documentation about EJS (Embedded JavaScript Templates)