You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
模板:
this is {{#if show1 == =show2}}{{title}}{{/if}}
数据:
{ title:'my' ,show1:0,show2:0}
渲染:
this is my
expression
{{#if a>b+1}}
{{a+2}}
模板:
this is
{{#each datas}}
{{key}} : {{value}}
{{/each}}
数据:
{ datas:[{key:1,value:2},{key:3,value:4}]}
渲染:
this is my : 1 u : 2
{{#with data}} {{/with}}
进一步支持 {{../x}}
模板:
this is
{{#with datas}}
{{my}} {{u}}
{{/with}}
数据:
{ datas:{ my:1,u:2 }}
渲染:
this is 1 2
{{! comment }}
模板:
this is {{! haha }}
数据:
{ datas:{ my:1,u:2 } }
渲染:
this is
{{#include}}
详见: addSubTemplate
escape syntax
模板:
my {{test}}
数据:
{test:2}
渲染:
my {{test}}
api
渲染
KISSY.Template('this is {{title}}').render({title:'2'})// => this is 2
自定义命令
KISSY.Template.addCommand('linkfy',function(url){return'<a>'+url+_'</a>';});KISSY.Template('this is {{linky url}}').render({url:'http://www.g.cn'})// => this is <a>http://www.g.cn</a>KISSY.Template.addCommand('if_less',function(num,num2,option){returnnum>num2?option.fn(option.context):option.inverse(option.context);});KISSY.Template('this is {{#if_less num1 num2}}{{url}}{{/if_less}}').render({url:'http://www.g.cn',num1:3,num2:2})// => this is http://www.g.cn
子模板
KISSY.Template.addSubTemplate('header','i am {{head}}');KISSY.Template('{{#include "header"}}').render({head:'2'})// => i am 2KISSY.Template.addSubTemplate('header2',function(all,context){returncontext.head;// 可进一步 KISSY.Template().render(context);});KISSY.Template('{{#include "header2" head="3"}}').render({head:'2'})// => i am 3
需求收集
语法
{{variable}}
模板:
this is {{title}}
数据:
{ title:'my' }
渲染:
this is my
{{#if condition}} {{else}} {{/if}}
condition 可进一步 > = < >= <= 等简单判断以及 * + - / ^
模板:
this is {{#if show}}{{title}}{{/if}}
数据:
{ title:'my' ,show:0}
渲染:
this is
{{#ifeq}}
模板:
this is {{#if show1 == =show2}}{{title}}{{/if}}
数据:
{ title:'my' ,show1:0,show2:0}
渲染:
this is my
expression
{{#if a>b+1}}
{{a+2}}
模板:
this is
{{#each datas}}
{{key}} : {{value}}
{{/each}}
数据:
{ datas:[{key:1,value:2},{key:3,value:4}]}
渲染:
this is my : 1 u : 2
{{#with data}} {{/with}}
进一步支持 {{../x}}
模板:
this is
{{#with datas}}
{{my}} {{u}}
{{/with}}
数据:
{ datas:{ my:1,u:2 }}
渲染:
this is 1 2
{{! comment }}
模板:
this is {{! haha }}
数据:
{ datas:{ my:1,u:2 } }
渲染:
this is
{{#include}}
详见: addSubTemplate
escape syntax
模板:
my {{test}}
数据:
{test:2}
渲染:
my {{test}}
api
渲染
自定义命令
子模板
预编译
KISSY 模块化机制结合
a 模板:
xx 模板:
编译后生成两个模块:
a:
xx:
kissy template 对比:
优势
劣势
refer
handlebar
closure template
velocity
XTemplate
The text was updated successfully, but these errors were encountered: