freemarker相关标签

<#if animals.python.price != 0>

       Pythons are not free today!

</#if>

 

<#if animals.python.price < animals.elephant.price>

           Pythons are cheaper than elephants today.

<#elseif animals.elephant.price < animals.python.price>

          Elephants are cheaper than pythons today.

<#else>

          Elephants and pythons cost the same today.

</#if>

 

上面示例中的一个问题是如果我们有0个水果,它仍然会输出一个空的 <ul></ul>,而不是什么都没有。 要避免这样的情况,可以这么来使用 list

<#list misc.fruits>

  <ul>

      <#items as fruit>

          <li>${fruit}

     </#items>

</ul>

</#list>

 

被 sep 覆盖的部分(我们也可以这么来写: ...<#sep>, </#sep></#list>) 只有当还有下一项时才会被执行。 因此最后一个水果后面不会有逗号:

<p>Fruits:

 <#list misc.fruits as fruit>

        ${fruit}<#sep>,

</#list>

 

假设要在一些页面中显示版权声明的信息。那么可以创建一个文件来单独包含这些版权声明, 之后在需要它的地方插入即可,

当需要用到文件时,可以使用 include 指令来插入:

<#include "/copyright_footer.html">

posted @ 2017-08-26 17:08  wanglittlehandsome  阅读(89)  评论(0编辑  收藏  举报