0.0.2 • Published 10 years ago
bemtmpl v0.0.2
JavaScript based, client-side, lightweight, simple templater for BEM
Declaration
Use .decl(name, templater)
method to declarate new template.
name
– the name of templatetemplater(ctx)
– function, which convert entry bemjson to htmlctx
– entry bemjson tree
BEMTMPL.decl('my-block', function(ctx) {
ctx.content(ctx.data, true);
});
Templating
BEMTMPL.apply({ block: 'my-block', data: 'azaza' });
Methods
ctx
object, that available inside templater, have several methods for modification entry
bemjson tree:
js
attr
mods
mix
content
All methods have same signature method([data][, force])
:
data
– data to modify self-named field of bemjson treeforce
– by default, field data was extended withdata
. Ifforce: true
, field value was replaced withdata
.
NOTE: force
doesn't work for mix
for ideological reasons.
Getters
If you don't specify the data
, all above methods return value of appropriate field.
ctx.mods(); // { theme: simple }
For attrs
and mods
you can specify the name of attribute or modifier that you want to get.
ctx.mods('theme'); // 'simple'