template-web.js 引用变量、函数(过滤器)、过滤器传参、输出html 模板

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>

更多详情请参考:  https://www.jianshu.com/p/d8d8e19157e0

原文地址:https://www.cnblogs.com/wangyihong/p/10155683.html