How to Use Macros in Freemarker

How to Use Macros in Freemarker

macros.ftl


<#macro greet>
<font color="red">Hello World</font>
</#macro>

<#macro greet1 person>
<font color="blue">Hello ${person}!</font>
</#macro>

<#macro greet2 person color="green">
<font color="${color}">Hello ${person}!</font>
</#macro>

<#macro border>
<table border=4 cellspacing=0 cellpadding=4><tr><td>
<#nested>
</tr></td></table>
</#macro>

<#macro thrice>
<#nested><br/>
<#nested><br/>
<#nested><br/>
</#macro>

<#macro twise>
<ul><li><#nested 1></li>
<li><#nested 2></li>
</ul>
</#macro>

form.ftl

<html>
<body>
<#include "macros.ftl">

<@greet/><br/>

<@greet1 person="santhi"/><br/>

<@greet2 person="prasanthi" color="orange"/>

<@border>Test</@border>

<@thrice>
Thrice.
</@thrice>

<@twise ; x>
${x}. Twise.
</@twise>

</body>
</html>

No comments: