Skip to content

Commit

Permalink
Docs: attrs templating hidden feature (for #423)
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Apr 16, 2018
1 parent 4ee9bbd commit ae23db1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/en/4-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,37 @@ Values are escaped:
<div id="anchor" name="Cartoon &quot;Tom &amp; Jerry&quot;"></div>
```

For any field value in `attrs` object templates will be applied. Example:

```js
// BEMJSON
{
block: 'button',
attrs: {
'data-text': {
block: 'i-bem',
elem: 'i18n',
key: 'button-success'
}
}
}
```

```js
// Template
block('i-bem').elem('i18n')({
// Here I18N.get it’s just method which returns some string
def: (node, ctx) => node.I18N.get(ctx.key)
});
```

*Result of templating:*

```html
<div id="button" data-text="Congratulations!"></div>
```


### cls

`{String}` HTML class or classes (separated by spaces) that do not belong to the BEM subject domain. For example, the use of [microformats](http://microformats.org/) or semantic markup from [schema.org](https://schema.org/).
Expand Down
31 changes: 31 additions & 0 deletions docs/ru/4-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,37 @@
<div id="anchor" name="Мультфильм &quot;Tom &amp; Jerry&quot;"></div>
```

Если любое поле объекта `attrs` содержит БЭМ-cущность (в данном случае просто объект с полями `block`/`elem`/`mods`/`elemMods`), то для такого объекта шаблонизатор попробует применить шаблоны. Пример:

```js
// BEMJSON
{
block: 'button',
attrs: {
'data-text': {
block: 'i-bem',
elem: 'i18n',
key: 'button-success'
}
}
}
```

```js
// Шаблон
block('i-bem').elem('i18n')({
// Здесь I18N.get просто метод, который возвратит строку
def: (node, ctx) => node.I18N.get(ctx.key)
});
```

*Результат шаблонизации:*

```html
<div id="button" data-text="Поздравляем!"></div>
```


### cls

`{String}` HTML-класс или классы (через пробел), не принадлежащие к предметной области БЭМ. Например, применение [микроформатов](http://microformats.org/) или семантической разметки из [schema.org](https://schema.org/).
Expand Down

0 comments on commit ae23db1

Please sign in to comment.