freemarker

字符串內建函數

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>
發佈了43 篇原創文章 · 獲贊 21 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章