首页 > 技术文章 > swig的语法和用法

alice-fee 2017-06-13 23:41 原文

1.swig一般在js文件里引入方法: __inline(*.tpl),如下图所示

2.特殊用法

swig模板里套用swig模板,<link rel="import" href="./*.tpl?__inline">.如下图,

3.swig里防止转译 {{ stringHtml|safe }}

 

4. swig的filter

filters.js:

swig.setFilter('numdate',function(timestr,option){
var date = new Date(parseInt(timestr)*1000 + 1000*60*60*8);
return date;
});

 

中国日期错误原因:

症状为明明是23号,用swig date filter后显示日期为22号。

原因是由于swig默认使用的国际标准时区,中国大于国际标准时区8个小时

解决方案:误差减去 480m

html:

{{ item.apply_time|numdate|date('Y-m-d H:i', -480) }}

  1.   <td>{= e.birthday|date('Y-m-d', -480) =}</td>  
  2.       <td>{= e.create_at|date('Y-m-d H:i:s', -480, 'CCT') =}</td>  

5. 随时提醒可以输入多少字符 string.length

<textarea name="company_publicity" id="company_publicity" cols="30" rows="10" placeholder="请输入公司文化">{{ company_publicity }}</textarea>
<p class="reply-prompt">你还可以输入<span class="char">{{ 300-company_publicity.length }}</span>个字符</p>

推荐阅读