JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q36448F
  • License MIT

Render Marko templates in a Fastify application.

Package Exports

  • @marko/fastify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@marko/fastify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


@marko/fastify
TypeScript Styled with prettier Build status NPM Version Downloads

Render Marko templates in a Fastify application.

Installation

npm install @marko/fastify

Examples

Setup

import fastify from "fastify";
import markoPlugin from "@marko/fastify";
import Template from "./template.marko";

const app = fastify();

app.register(markoPlugin);

app.get("/", (request, reply) => {
  // Streams Marko template into the response.
  // Forwards errors into fa error handler.
  reply.marko(Template, { hello: "world" });
});

$global / out.global

When calling reply.marko the input.$global is automatically merged with app.locals and reply.locals (both added by this plugin). This makes it easy to set some global data via fastify hook or globally, eg:

app.locals.appName = "My App";

app.addHook("onRequest", (request, reply, done) => {
  reply.locals.locale = "en-US";
  reply.locals.serializedGlobals.locale = true;
  done();
});

Then later in a template access via:

<div>${out.global.appName}: ${out.global.locale}</div>

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.