asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
<#-- call the macro; the macro variable is already created: -->
<@test2 />
...
<#-- create the macro variable: -->
<#macro test2>
  Test text
</#macro>
<#-- call the macro: -->
<@test foo="a" bar="b" baaz=5*8-2 />
<#macro test foo bar baaz>
  Test text, and the params: ${foo}, ${bar}, ${baaz}
</#macro>
 <#macro img src extra...>
  <img src="${src?html}"
  <#list extra?keys as attr>
    ${attr}="${extra[attr]?html}"
  </#list>
  >
</#macro>
<@img src="http://www.21cp.net/images/logo_nav.gif" width=100 height=50 alt="Test"/>
posted on 2008-10-07 15:35 汪杰 阅读(341) 评论(3)  编辑 收藏 引用 所属分类: freemarker

FeedBack:
# re: macro
2008-10-07 16:35 | 汪杰
Example:



<#macro do_twice>
1. <#nested>
2. <#nested>
</#macro>
<@do_twice>something</@do_twice>




Output:



1. something
2. something





The nested directive can create loop variables for the nested content. For example:



<#macro do_thrice>
<#nested 1>
<#nested 2>
<#nested 3>
</#macro>
<@do_thrice ; x>
${x} Anything.
</@do_thrice>




This will print:



1 Anything.
2 Anything.
3 Anything.





A more complex example:



<#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>




The output will be:



1. 0.5
2. 1
3. 1.5
4. 2 Last!


  回复  更多评论
  
# re: macro
只有注册用户登录后才能发表评论。

<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 456688
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜