Package Exports
- @marko/express
Readme
@marko/express
Render Marko templates in an express
application.
Installation
npm install @marko/express
Examples
Setup
import express from "express";
import markoMiddleware from "@marko/express";
import Template from "./template.marko";
const app = express();
app.use(markoMiddleware());
app.get("/", (req, res) => {
// Streams Marko template into the response.
// Forwards errors into expresses error handler.
res.marko(Template, { hello: "world" });
});
$global / out.global
When calling res.marko
the input.$global
is automatically merged with app.locals
and res.locals
from express
. This makes it easy to set some global data via express middleware, eg:
middleware.js
export default (req, res, next) => {
res.locals.locale = "en-US";
};
Then later in a template access via:
<div>${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.