-
Notifications
You must be signed in to change notification settings - Fork 172
LayoutManager in Node.js
LayoutManager is fully compatible with Node.js. This means you can use the same API for rendering HTML on the server!
Please see the Installation section for details on how to install LayoutManager for use in Node.js.
LayoutManager is included via Node.js's require
API:
var LayoutManager = require("backbone.layoutmanager");
LayoutManager will use its own instance of Backbone.js unless you have installed Backbone.js prior to installing LayoutManager.
Besides the special considerations listed below, usage of LayoutManager in Node.js is identical to usage in the browser.
Because LayoutManager code traditionally runs in the browser, there are a number of conventions that should be avoided when writing code for Node.js:
-
DOM: Simply put, there is no Document Object Model in Node.js. A view's
el
property may not function as it does in the browser. Additionally, DOM events like “click” or “focus” will neither bind nor trigger.o traverse and manipulate HTML structures. -
jQuery: LayoutManager uses the cheerio library to render and traverse HTML structures. You can access Cheerio via
LayoutManager.$
, but please refer to the Cheerio documentation for details regarding API parity with jQuery. -
Promises API: In Node.js, LayoutManager relies on the underscore.deferred library's implementation of
when
andDeferred
.
We've configured LayoutManager to work naturally when running in Node.js. This includes overrides to the following methods:
-
fetchTemplate
reads from the filesystem -
partial
uses Cheerio
As always, you can override these methods as you please; see the documentation on Configuration for more details.
Node.js support would not be possible without the help of these fine libraries:
- Cheerio for a fast Node.js implementation of the jQuery API
- underscore.deferred for a Node.js-ready implementation of the Common.js Promises/A Spec.
Getting started
Usage
- Overview
- Configuration
- Basics
- Example usage
- Nested views
- Template rendering
- LayoutManager in Node.js
API reference
Migration guides
Legacy
How to contribute