Render Marko templates in an express application.
npm install @marko/expressRender Marko templates in an express application.
``console`
npm install @marko/express
`javascript
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" });
});
`
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_
`js`
export default (req, res, next) => {
res.locals.locale = "en-US";
};
Then later in a template access via:
`marko`${out.global.locale}
Allows res.redirect to redirect HTML responses that have already begun sending content. This is done by flushing a tag redirect with a
});
``
This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.