freemarker

来源:互联网 发布:微商软件总代理 编辑:程序博客网 时间:2024/06/06 02:44

字符串内建函数

1.声明两个字符串

<#assign a='hello'/><#assign b='world'/>

2.内键函数

  连接    +            ${a+b}  截取   substring     ${(a+b)?substring(5,6)}    长度   ?length      ${(a+b)?length}  大写   ?upper_case  ${(a+b)?upper_case}  小写   ?lower        ${(a+b)?lower}字母出现的位置  ?index_of     ${(a+b)?index_of('o')}  替换      ?replace     ${(a+b)?replace('0','xx')} 将o替换为xx

具体使用:

<ul>  <#assign a='hello'>  <#assign b='world!'>  <li>连接</li>  <font color="red" size="18px">${a+b}</font><br/>  <li>截取</li>  <font color="blue" size="18px">${(a+b)?substring(5,8)}</font><br/>  <li>长度</li>  <font color="red" size="18px">${(a+b)?length}</font><br/>  <li>大写</li>  <font color="blue" size="18px">${(a+b)?upper_case}</font><br/>  <li>小写</li>  <font color="red" size="18px">${(a+b)?lower_case}</font><br/>  <li>index_of</li>  <font color="blue" size="18px">${(a+b)?index_of('w')}</font><br/>  <li>replace</li>  <font color="red" size="18px">${(a+b)?replace('o','abc')}</font><br/>  <li>last_index_of</li>  <font color="blue" size="18px">${(a+b)?last_index_of('o')}</font><br/></ul>

chunk函数用法(list)

| 说明:可以将某个list集合按照某几个元素一块再次划分

<#list list?chunk(2) as article>                            <div class="row">                                <div class="col-md-6 col-sm-6">                                    <article class=" blog-teaser">                                        <header>                                            <img src="img/4.jpg" alt="">                                            <h3><a href="">${article[0].blog_title!}</a></h3>                                            <span class="meta">${article[0].update_time?date}</span>                                            <hr>                                        </header>                                    </article>                                </div>                                <#if article[1]?exists>                                <div class="col-md-6 col-sm-6">                                    <article class=" blog-teaser">                                        <header>                                            <img src="img/3.jpg" alt="">                                            <h3><a href="">${article[1].blog_title !}</a></h3>                                            <span class="meta">${article[1].update_time?date}</span>                                            <hr>                                        </header>                                    </article>                                </div>                                </#if>                            </div></#list>