Primate Logo Primate
Guides Components

Use Handlebars

Add Handlebars templating with the @primate/handlebars module.

1) Install

Install the Primate Handlebars package.

npm i @primate/handlebars

2) Configure

Load the Handlebars module in your configuration.

import config from "primate/config";
import handlebars from "@primate/handlebars";

export default config({
  modules: [
    handlebars(),
  ],
});

3) Write a template

Compose a template in Handlebars.

<!-- components/Welcome.hbs -->
<h1>Hello, {{name}}!</h1>

4) Render the template

Use response.view in a route to render the template.

// routes/index.ts
import route from "primate/route";
import response from "primate/response";

export default route({
  get() {
    return response.view("Welcome.hbs", { name: "World" });
  },
});