L
L
lavezzi12015-12-30 15:29:37
css
lavezzi1, 2015-12-30 15:29:37

Alternative to html template from Bem?

Hello. Please tell me html template engines are very similar in their logic to bem tools, that is, in which you can create blocks on the page through json and, accordingly, so that this code is converted into an html page.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Ineshin, 2015-12-30
@IonDen

It's not generally accepted practice to generate HTML this way. Look at other solutions: Jade
preprocessors
, Haml
Template engines:
habrahabr.ru/post/219873

I
i, 2016-01-15
@ilyarsoftware

Anyone, more specifically in your case with JSON support, such as NANO , although roughly speaking closer to BH/BEMHTML , can be called json2html , an example of using json2html with CSS from bem-components:

var data = [
  {
    'text': 'BEM — BEM Easy Makeup',
    'url': 'https://ru.bem.info/',
  },
];

var template = {
  tag: 'a',
  class: 'button button_theme_islands button_size_xl',
  href: '${url}',
  children: [
    {
      tag: 'span',
      class: 'icon icon_social_twitter',
    },
    {
      tag: 'span',
      class: 'button__text',
      html: '${text}',
    },
  ]
};
document.body.innerHTML = json2html.transform( data, template );

Demo on jsfiddle
I'm sure there are others, but all of them will not know about BEM terms and therefore you will have to add hepers to work with sides, elements, modifiers, etc.
At the moment, I don't know anything more convenient than BH / BEMHTML, but if such a template engine appears, it will be published in the section bem.info/BEM projects .

V
Vasyl Kovbassa, 2016-12-17
@movasyl

lavezzi1 , Jade / pug you won't find anything better. It already went through a month ago. Now I don’t understand how I lived without it for so many years :))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question