freemarker常用标签解释
2024-08-24 20:57:10
标签一: 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)
最新文章
- 应用Grunt自动化地优化你的项目前端
- ASP.NET MVC的客户端验证:jQuery的验证
- 50个C/C++源代码网站(转-清风小阁)
- PHP数组操作大全
- POJ 2021 Relative Relatives(map+树的遍历)
- python autopy
- 2D UI和3D UI的工作原理
- (转载).Net HttpPost的发送和接收示例代码
- 树莓派(jessie)制作服务并开机启动
- Table XXX is marked as crashed and should be repaired问题
- sql server 2012提示评估期已过的解决办法 附序列号
- HDU 2955 Robberies(01背包)
- SQL---存储过程---存储过程编写案例
- C#从SqlServer数据库读写文件源码
- centos7将网卡名字改成eth样式
- Apache Ant 项目构建
- OpenRASP安装使用教程
- kafka集群压力测试--基础。
- 08python之列表的常用方法
- Oracle EBS Model Function Technical
热门文章
- 为什么in_array(0, [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;])返回true
- 在Google Colab中导入一个本地模块或.py文件
- Solaris11修改主机名
- 问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题
- LaTex: 表格单元格内容 分行显示/换行
- return()函数
- 01 json环境搭建【spring + pringMVC】
- java全栈day01-01
- 发现C#winform编程中不常用的控件(一)<;FlowLayoutPanel控件>;<;拆分器控件Splitcontainer >;
- HDU 1796 How many integers can you find (容斥)