Skip to content

Instantly share code, notes, and snippets.

@innabelaya
Last active August 29, 2015 14:27
Show Gist options
  • Save innabelaya/d17e2185b89799595844 to your computer and use it in GitHub Desktop.
Save innabelaya/d17e2185b89799595844 to your computer and use it in GitHub Desktop.

Исполнение шаблонов в браузере

Скомпилированный файл подключается на страницу как JavaScript-файл.

<script src="bundle.bemtree.js"></script>
<script src="bundle.bemhtml.js"></script>

В браузере исполнение шаблонов зависит от наличия модульной системы:

  • Без модульной системы

    Шаблоны доступны из глобальной переменной BEMHTML или BEMTREE.

    BEMTREE.apply({ block: 'page', data: { /* ... */ } })
        .then(function (bemjson) {
            var html = BEMHTML.apply(bemjson);
        });
  • С модульной системой YModules

    Шаблоны доступны из модульной системы (YModules):

    modules.require(['BEMTREE', 'BEMHTML'], function(BEMTREE, BEMHTML) {
        BEMTREE.apply({ block: 'page', data: { /* ... */ } })
            .then(function (bemjson) {
                var html = BEMHTML.apply(bemjson);
            });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment