Quick start
Installation
To use bem-xjst, you need Node.js v0.10 or later, and npm.
Install:
npm install bem-xjst
Basic example
var bemxjst = require('bem-xjst');
// bem-xjst contains two engines, BEMHTML and BEMTREE (starting from v5.0.0)
// Choose the BEMHTML engine
var bemhtml = bemxjst.bemhtml;
// Add templates using the `compile` method
var templates = bemhtml.compile(function() {
block('text').tag()('span');
});
// Add data in BEMJSON format
var bemjson = [
{ block: 'text', content: 'First' },
{ block: 'text', content: 'Second' }
];
// Apply templates
var html = templates.apply(bemjson);
The resulting html
contains this string:
<span class="text">First</span><span class="text">Second</span>
Read next: API