xtemplate 宏命令使用示例

Class

xtemplate 宏命令使用示例

KISSY.use('xtemplate', function (S, XTemplate) {

    window.supportMacro = function () {
        var tpl = '{{#macro "test" "t"}}{{t}}{{/macro}}call {{macro "test" arg}}';
        var render = new XTemplate(tpl).render({
            arg: 'macro'
        });
        alert(render);
    };

});

xtemplate 使用父模板的宏命令

KISSY.use('xtemplate', function (S, XTemplate) {

    window.supportMacro = function () {
        var tpl = '{{#macro "test" "t"}}{{t}}2{{/macro}}{{include "macro/x2"}}';
        KISSY.add('macro/x2', 'call {{macro "test" arg}}');
        var render = new XTemplate(tpl).render({
            arg: 'macro'
        });
        alert(render);
    };

});

xtemplate 使用子模板的宏命令

KISSY.use('xtemplate', function (S, XTemplate) {

    window.supportMacro = function () {
        var tpl = '{{include "macro/x"}}call {{macro "test" arg}}';
        KISSY.add('macro/x', '{{#macro "test" "t"}}{{t}}{{/macro}}');
        var render = new XTemplate(tpl).render({
            arg: 'macro'
        });
        alert(render);
    };

});