Skip to content

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.

Terminal window
npm install @gaman/edge edge

Add the edge middleware to your application:

index.ts
import { edge } from "@gaman/edge";
defineBootstrap((app) => {
app.mount(
edge({
viewPath: "src/views",
})
);
});

Create a file src/views/index.edge

<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>Hello, {{ name }}</h1>
</body>
</html>

In your route handler, use Res.render():

AppRoutes.ts
route.get("/", (ctx) => {
return Res.render("index", {
title: "My First Edge Page",
name: "GamanJS 🚀"
});
});

Here we provide what’s called composeEdgeHandler which functions to create templates and other edge environments.

Create a file with any name

EdgeHandler.ts
import { composeEdgeHandler } from "@gaman/edge"
export default composeEdgeHandler((edge) => {
edge.global('config', {
colorScheme: 'dark',
menu: [],
socialLinks: [],
});
});

Then in index.ts do this:

index.ts
import { EdgeHandler } from "./EdgeHandler.ts"
defineBootstrap(async (app) => {
app.mount(
edge({
handler: EdgeHandler
})
)
});
NameTypeDefaultDescription
viewPathstring"src/views"Root directory where Edge templates are located.
handler(edge) => {}undefinedEdge handler

Please read more detailed documentation about Edge.js