Skip to main content
Home

Built and signed on GitHub Actions

Handlebar renderer for Deno

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
9 months ago (0.0.3)

Handlebars template render for Deno

test

Official handlebars docs: Guide

How to use renderer

import { Handlebars, HandlebarsConfig } from "jsr:@danet/handlebars";

// First, create instance of Handlebars

const handle = new Handlebars();

// or with custom config
const handle = new Handlebars({
    ...
});

// by default uses this config:
const DEFAULT_HANDLEBARS_CONFIG: HandlebarsConfig = {
    baseDir: 'views',
    extname: '.hbs',
    layoutsDir: 'layouts/',
    partialsDir: 'partials/',
    cachePartials: true,
    defaultLayout: 'main',
    helpers: undefined,
    compilerOptions: undefined,
};

// then render page
import { Application, Router } from 'jsr:@oak/oak';
const app = new Application();
const router = new Router();
app.use(async function(ctx, next) {
    ctx.state.handlebars = new Handlebars();
    await next();
});
router.get('/', async function(ctx) {
    ctx.response.body = await ctx.state.handlebars.renderView('index', { name: 'Alosaur' });
);

Rendering in development mode

By default partials are registered (and so cached) the first time you call renderView. However, in development, it may be better to re-register them every time you render a view so that the rendering reflects the latest changes you have made to your partials.

You can ensure this happens by setting cachePartials to be false in your configuration.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";
or

Import directly with a jsr specifier

import * as handlebars from "jsr:@danet/handlebars";

Add Package

pnpm i jsr:@danet/handlebars
or (using pnpm 10.8 or older)
pnpm dlx jsr add @danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";

Add Package

yarn add jsr:@danet/handlebars
or (using Yarn 4.8 or older)
yarn dlx jsr add @danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";

Add Package

vlt install jsr:@danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";

Add Package

npx jsr add @danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";

Add Package

bunx jsr add @danet/handlebars

Import symbol

import * as handlebars from "@danet/handlebars";