Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 2.99 KB

dispatcher.md

File metadata and controls

45 lines (35 loc) · 2.99 KB

fluid.handlebars.dispatcherMiddleware

fluid.express.middleware that renders content using a page template and/or layout based on the URL path. The dispatcher turns the last part of a path (such as /dispatcher/foo) into a template name (such as foo), and then attempts to find and render that template. The templates available to the dispatcher are configured in the options for the enclosing fluid.express.hb instance.

If a template matching the path can be found, it will be used to render the page. If the last part of the path is omitted, the template configured by options.defaultTemplate will be used. If a layout with the same name is found, that will be used, otherwise, the layout found at options.defaultLayout will be used.

If the last part of the path is supplied but does not match any templates, a 404 error is passed along the middleware chain, which will be handled by the next piece of error middleware in the stack.

Component Options

This component supports the options available for any fluid.express.middleware instance. In addition, this component supports the following configuration options:

Option Type Description
defaultTemplate String The name of the default template to use when the template name is omitted, minus the extension.
defaultLayout String The name of the default layout to use when no template matching :template is found. Defaults to index.handlebars
rules.contextToExpose Object Model transformation rules that control what information is exposed to the renderer. The rules can make use of the request object (req) and the dispatcher's model (model).

Component Invokers

{that}.middleware(request, response, next)

Implements the middleware function required by the fluid.express.middleware grade