Forum

Methodology

Toolbox

Platform

Community

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>

Online demo.

Read next: API

If you notice a mistake or want something to supplement the article, you can always write to us at GitHub, or correct an article using prose.io.