标签一: if else

你可以使用if,elseif和else指令来条件判断是否越过模板的一个部分。这些condition-s必须计算成布尔值,否则错误将会中止模板处理。elseif-s和else-s必须出现在if的内部(也就是,在if的开始标签和技术标签之间)。if中可以包含任意数量的elseif-s(包括0个)而且结束时else是可选的。

<#if x == 1>
  x is
</#if>
<#if x == 1>
  x is
<#else>
  x is not
</#if>
<#if x == 1>
  x is
<#elseif x == >
  x is
<#elseif x == >
  x is
</#if>
<#if x == 1>
  x is
<#elseif x == >
  x is
<#elseif x == >
  x is
<#elseif x == >
  x is
<#else>
  x is not nor nor nor
</#if>

当然你也可以嵌套使用

<#if x == 1>
  x is
  <#if y == 1>
  and y is too
  <#else>
  but y is not
  </#if>
<#else>
  x is not
  <#if y < 0>
  and y is less than
  </#if>
</#if>

2 switch,case,default,break指令

<#switch being.size>
  <#case "small">
  This will be processed if it is small
  <#break>
  <#case "medium">
  This will be processed if it is medium
  <#break>
  <#case "large">
  This will be processed if it is large
  <#break>
  <#default>
  This will be processed if it is neither
</#switch>

3 list,break 指令

  

<#assign seq = ["winter", "spring", "summer", "autumn"]>
<#list seq as x>
  ${x_index + }. ${x}<#if x_has_next>,</#if>
</#list>

4 include指令

<#assign me = "Juila Smith">
<h1>Some test</h1>
<p>Yeah.
<hr>
<#include "/common/copyright.ftl">

5 compress指令

<#assign x = " moo \n\n ">
(<#compress> ${moo}
test only
I said, test only
</#compress>)

当你使用了对空白不敏感的格式(比如HTML或XML)时压缩指令对于移除多余的空白是很有用的。它捕捉在指令体(也就是在开始标签和结束标签中)中生成的内容,然后缩小所有不间断的空白序列到一个单独的空白字符。如果被替代的序列包含换行符或是一段空间,那么被插入的字符也会是一个换行符。开头和结尾的不间断的空白序列将会完全被移除。

上面输出结果为:

(
moo
test only
I said, test only)

最新文章

  1. 应用Grunt自动化地优化你的项目前端
  2. ASP.NET MVC的客户端验证:jQuery的验证
  3. 50个C/C++源代码网站(转-清风小阁)
  4. PHP数组操作大全
  5. POJ 2021 Relative Relatives(map+树的遍历)
  6. python autopy
  7. 2D UI和3D UI的工作原理
  8. (转载).Net HttpPost的发送和接收示例代码
  9. 树莓派(jessie)制作服务并开机启动
  10. Table XXX is marked as crashed and should be repaired问题
  11. sql server 2012提示评估期已过的解决办法 附序列号
  12. HDU 2955 Robberies(01背包)
  13. SQL---存储过程---存储过程编写案例
  14. C#从SqlServer数据库读写文件源码
  15. centos7将网卡名字改成eth样式
  16. Apache Ant 项目构建
  17. OpenRASP安装使用教程
  18. kafka集群压力测试--基础。
  19. 08python之列表的常用方法
  20. Oracle EBS Model Function Technical

热门文章

  1. 为什么in_array(0, [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])返回true
  2. 在Google Colab中导入一个本地模块或.py文件
  3. Solaris11修改主机名
  4. 问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题
  5. LaTex: 表格单元格内容 分行显示/换行
  6. return()函数
  7. 01 json环境搭建【spring + pringMVC】
  8. java全栈day01-01
  9. 发现C#winform编程中不常用的控件(一)&lt;FlowLayoutPanel控件&gt;&lt;拆分器控件Splitcontainer &gt;
  10. HDU 1796 How many integers can you find (容斥)