A Template View Engine for Deno frameworks
- Support multiple templating engines📰
- Current support Denjucks, Eta, Handlebars, and dejs,
- Engines can be used standalone🎙 - Use standlone handlebar engine
- Framework neutral🎨, it uses adapter to load engine
- Current support Oak
- Local file⛱ loading
Ashychorous⚡ remote file fetching (fetching template on the fly )- Dynamic module import, uses
await
to load adapters and engines🌈
viewEngine(
adapter: Adapter,
engine:Engine,
viewConfig?: ViewConfig
)
import { oakAdapter } from "https://deno.land/x/[email protected]/mod.ts"
import { ejsEngine, denjuckEngine, handlebarsEngine } from "https://deno.land/x/[email protected]/mod.ts"
const viewConfig: ViewConfig = {
viewRoot: <string>"./views", // default: "", specify the root path, it can be remote address
}
Use Oak to render eta
template at ./views/eta/index.eta
Suppose you have a folder like this:
/views/index.ejs
/app.ts
<!--index.html-->
<body>
Hobbies of <%=it.name%>
</body>
// app.ts
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
import { viewEngine, ejsEngine, oakAdapter } from "https://deno.land/x/[email protected]/mod.ts"
const app = new Application();
app.use(
viewEngine(oakAdapter, etaEngine, {
viewRoot: "./views/eta",
})
);
app.use(async (ctx, next) => {
ctx.render("index.eta", { name: "John" } );
});
await app.listen({ port: 8000 });
Then run
> deno run --allow-net --allow-read ./app.ts
Open any browser, url: http://localhost:8000
you should see the result.
Original work by @gjuoun