1.關鍵字 $imports.+變量/函數
{{if $imports.myParseInt(b.health_money)}} <span class="num">+{{b.health_money}}積分</span> {{else}} <span class="num org">{{b.health_money}}積分</span> {{/if}}
<img src="{{$imports.url+ data.img}}" alt="">
2.拓展方法(過濾器)
template.defaults.imports.+方法名 = function ( 參數 ) {
}
template.defaults.imports.myParseInt = function (str) { if ( parseInt(str) > 0 ) { return 1; } else { return 0; } };
使用
<span class="num org">{{b.health_money | myParseInt}}</span>
2.拓展方法(過濾器),產多個參數
template.defaults.imports.tailFour = function (a,b,c) {
...
};
使用 (多個參數以逗號隔開)
<div>{{ a|tailFour:b,c }}</div>
4.輸出html 模板
第一種方法: 將{{content}}寫成 {{#content}}
第二種方法:template.config("escape", false);
<div class="content"> {{#content}} </div>