freemaker宏的用法
freemaker宏
定义:定义一个标签,标签体中可以包含参数,开始标签和结束标签可以包含内容,内容中可以通过${}方式引用标签体中定义的参数
用法:页面引入标签,通过标签可以直接输出标签的内容
HelloWorld实现
定义html.ftl:
<#macro html title>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>${title}</title>
<link rel="stylesheet" rev="stylesheet" href="/oa/file/css.css" type="text/css" media="all" />
</head>
<body>
<#nested/>
</body>
</html>
</#macro>
用法:
<#import "/WEB-INF/template/common/common.ftl" as c> <@c.html title="OA">
你的内容
</@c.html>
输出结果:
<#macro html title>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<title>${title}</title>
<link rel="stylesheet" rev="stylesheet" href="/oa/file/css.css" type="text/css" media="all" />
</head>
<body>
你的内容
</body>
</html>
</#macro>
相关语法
1.macro
<#macro name param1 param2 ... paramN>
用例
<#macro test foo bar="Bar" baaz=-1>
Test text, and the params: ${foo}, ${bar}, ${baaz}
</#macro>
<@test foo="a" bar="b" baaz=5*5-2/>
<@test foo="a" bar="b"/>
<@test foo="a" baaz=5*5-2/>
<@test foo="a"/>
输出
Test text, and the params: a, b, 23
Test text, and the params: a, b, -1
Test text, and the params: a, Bar, 23
Test text, and the params: a, Bar, -1
2.nested(<#macro name param1 param2 ... paramN;x y z> )xyz为nested 标签定义的内容,nested 相当于标签内容的占位符
<#macro repeat count>
<#list 1..count as x>
<#nested x, x/2, x==count>
</#list>
</#macro>
<@repeat count=4 ; c halfc last>
${c}. ${halfc}<#if last> Last!</#if>
</@repeat>
输出
1. 0.5
2. 1
3. 1.5
4. 2 Last!
3.循环
<#macro list title items>
<p>${title?cap_first}:
<ul>
<#list items as x>
<li>${x?cap_first}
</#list>
</ul>
</#macro>
<@list items=["mouse", "elephant", "python"] title="Animals"/>
输出结果
<p>Animals:
<ul>
<li>Mouse
<li>Elephant
<li>Python
</ul>
参考链接
http://tdcq.iteye.com/blog/748266
freemaker宏的用法的更多相关文章
- 完善_IO, _IOR, _IOW, _IOWR 宏的用法与解析
_IO, _IOR, _IOW, _IOWR 宏的用法与解析 原文地址:http://www.eefocus.com/ayayayaya/blog/12-03/245777_20cdd.html 作 ...
- C/C++宏的用法
今天看caffe源码的时候看到了很多宏定义的内容,苦于代码基础薄弱,无法全部理解,故在网上搜得此篇好文,转载一发附原文地址:http://blog.csdn.net/hanchaoman/articl ...
- _IO, _IOR, _IOW, _IOWR 宏的用法与解析
转载:http://blog.chinaunix.net/uid-20754793-id-177774.html 今天在写字符驱动验证程序的时候要用到ioctl函数,其中有一个cmd参数,搞了半天也不 ...
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析(引用)
在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设备驱动程序请求处理内容的值.cmd除了可区别数字外,还包含有助于处理的几种相应信息. cmd的大小为 32位,共分 4 个 ...
- Objective-C中系统宏的用法总结
先说一下本文中会提到的内容:##,__VA_ARGS__, __FILE__, __LINE__ , __FUNCTION__等 宏变量: 先举一个例子,会用到上面这些宏: #define mypri ...
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析
在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设备驱动程序请求处理内容的值.cmd除了可区别数字外,还包含有助于处理的几种相应信息. cmd的大小为 32位,共分 4 个 ...
- Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法与解析【转】
转自:http://blog.csdn.net/hzn407487204/article/details/7995041 在驱动程序里, ioctl() 函数上传送的变量 cmd 是应用程序用于区别设 ...
- Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_RE ...
- cocos2d-x系列笔记技巧篇(2)---关于CREATE_FUNC宏的用法
FROM://http://blog.csdn.net/jinciyulang/article/details/8631889 阅读cocos2d-x demo的代码,我们会看到有些头文件中使用CRE ...
随机推荐
- MapReduce-PRODUCTION-DEMAND
[粗暴的HIVE-SQL]select xyz from abc where ty='sdk' and ret_code=0 and data_source_type=1 and dt between ...
- (图解)Description Resource Path Location Type Java compiler level does not match the version of
Description Resource Path Location Type Java compiler level does not match the version of project 编译 ...
- hdoj 1116 Play on Words 【并查集】+【欧拉路】
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 腾讯云上运行java程序过程
1: 购买服务器(腾讯云,阿里云等) 2:安装centos操作系统: 3:安装jdkhttp://www.cnblogs.com/Amos-Turing/p/7403696.html 4:安装数据库( ...
- redux和mobx比较(一)
Redux vs Mobx 那么具体到这两种模型,又有一些特定的优缺点呈现出来,先谈谈 Redux 的优势: 数据流流动很自然,因为任何 dispatch 都会导致广播,需要依据对象引用是否变化来控制 ...
- sourceSet
android { sourceSets { main{ manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources ...
- debian下编译openwrt固件
参考文章:Ubuntu下编译OpenWRT固件 我买的路由器是RG100A-AA,采用了bcm63xx系列的芯片. 下载openwrt源码: svn co svn://svn.openwrt.org/ ...
- 9.2 NOIP提高组试题精解(1)
9-16 poise.c #include <stdio.h> #define MAXN 1001 int main() { ], flag[MAXN] = { }; //保存6种砝码的数 ...
- 简洁多用途SuperSlide插件—tab标签样式
简洁多用途SuperSlide插件—tab标签切换代码样式,由huiyi8素材网提供. 源码:http://www.huiyi8.com/tab/
- 谷歌新操作系统fuchsia
开源地址: https://github.com/fuchsia-mirror