Edge
@gaman/edge is the official middleware for integrating Edge Engine as a view engine in the GamanJS framework.
With this, you can render .edge template files (or other extensions) directly from controllers/handlers using GamanJS’s built-in view system.
Installation
Section titled “Installation”npm install @gaman/edge edgepnpm install @gaman/edge edgeyarn install @gaman/edge edgebun install @gaman/edge edgeRegister Edge
Section titled “Register Edge”Add the edge middleware to your application:
import { edge } from "@gaman/edge";
defineBootstrap((app) => { app.mount( edge({ viewPath: "src/views", }) );});Creating a Template
Section titled “Creating a Template”Create a file src/views/index.edge
<!DOCTYPE html><html> <head> <title>{{ title }}</title> </head> <body> <h1>Hello, {{ name }}</h1> </body></html>Rendering from a Route
Section titled “Rendering from a Route”In your route handler, use Res.render():
route.get("/", (ctx) => { return Res.render("index", { title: "My First Edge Page", name: "GamanJS 🚀" });});Edge Handler
Section titled “Edge Handler”Here we provide what’s called composeEdgeHandler which functions to create templates and other edge environments.
composeEdgeHandler()
Section titled “composeEdgeHandler()”Create a file with any name
import { composeEdgeHandler } from "@gaman/edge"
export default composeEdgeHandler((edge) => { edge.global('config', { colorScheme: 'dark', menu: [], socialLinks: [], });});Then in index.ts do this:
import { EdgeHandler } from "./EdgeHandler.ts"
defineBootstrap(async (app) => { app.mount( edge({ handler: EdgeHandler }) )});Config Options
Section titled “Config Options”| Name | Type | Default | Description |
|---|---|---|---|
viewPath | string | "src/views" | Root directory where Edge templates are located. |
handler | (edge) => {} | undefined | Edge handler |
Please read more detailed documentation about Edge.js