@gaman ejs - 7TogkID/gaman GitHub Wiki
GamanJS integration for EJS view rendering. Simplify template rendering using EJS.
- Integrates EJS template rendering into GamanJS applications.
- Fully customizable options passed to the EJS renderer.
- Supports custom view directories and other EJS configuration options.
Install the package using your favorite package manager:
npm install @gaman/ejs ejs
Configure the EJS integration in your main.ts
file:
import ejs from "@gaman/ejs";
import gaman from "gaman";
import blocks from "./blocks";
gaman.serv({
integrations: [
ejs({
viewPath: "custom/views", // Default is 'src/views'
// Additional EJS options can be configured here
}),
],
blocks: [blocks],
});
Add EJS templates in the src/views
directory (or your custom directory if configured).
File: src/views/index.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %></title>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to your GamanJS app with EJS integration!</p>
</body>
</html>
In your blocks file (e.g., main.block.ts
or example.block.ts
):
import { defineBlock, Response } from "gaman";
export default defineBlock({
routes: {
"/": async (ctx) => {
return Response.render("index", { title: "Welcome to GamanJS" });
},
},
});
EJS options can be customized through the integration. Refer to the full list of EJS options at the official EJS documentation.
Option | Type | Description | Default |
---|---|---|---|
viewPath |
string |
Root directory for your EJS templates. | src/views |
priority |
Priority |
Priority for this integration in GamanJS. | normal |
src/
├── blocks/
│ └── main.block.ts
├── views/
│ └── index.ejs
└── main.ts
EJS (Embedded JavaScript) is a simple templating language that lets you generate HTML markup with plain JavaScript.
This integration simplifies using EJS in GamanJS applications, letting you render views directly in your routes.
Seamlessly integrate EJS templates into your GamanJS projects with @gaman/ejs!