The View Engine Unit


extends:  libflitter/Unit

Flitter uses Pug as a view engine. This unit configures the underlying Express app to use it and creates a global function to serve a view.

go(express app, function next)

overrides:  super.go()         returns:  undefined

Initializes the unit. Configures the underlying Express app to use the Pug view engine. Flitter doesn't change the way Express looks for views, so they should all go within the views/ directory. Also creates a function to serve up views by name and makes it globally available in the ViewEngine context, then it executes the next function in the stack under it.

ViewEngine Context

This context provides access to the global view() function and configures the underlying Express app to use Pug as a view engine.

global.view(express.response response, String view_name, Object args)

returns:  mixed

Looks up a view with the specified view_name and renders it. View names follow the Flitter convention for sub-directory naming, so the view name auth:Login will render the view file views/auth/Login.pug. Any key-value pairs passed in the args object are passed along to the view such that the keys become variable names with their respective values. For example, the args object { username: "johndoe" } would make the username variable available in the view, like so: {{ username }}. The response should be passed in from the function that calls this one. Calling this function will send a response as it invokes express.response.render().

No Comments
Back to top