Re: weird macro params issue

Denis Bredelet <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
 
On Saturday, May 03, 2008, at 07:15PM, "Ioannis Cherouvim" <[email protected]> wrote:
>Hello again
>
>I know it's a corner case, and maybe a cryptic way of defining 
>templates, but here is how I actually use it:
>
><#macro renderLink url anchor=url title=anchor>
>    <a href="${url}" title="${title}">${anchor}</a>
></#macro>

I do not think that FreeMarker allows optional parameters otherwise you could do:

<#macro renderLink url anchor title>
    <#assign anchor=anchor!url>
    <a href="${url}" title="${title!anchor}">${anchor}</a>
</#macro>

-- Denis.

>
>This provides full flexibility for the client code of the renderLink 
>macro which has sensible defaults.
>All the following produce nice results:
><@renderLink "http://freemarker.sourceforge.net/" />
><@renderLink "http://freemarker.sourceforge.net/" "FreeMarker" />
><@renderLink "http://freemarker.sourceforge.net/" "FreeMarker" 
>"FreeMarker: Java Template Engine Library" />
>
>Of course I could rewrite the macro definition and implement the same 
>behavior with a couple of <#if /> and <#local /> inside it.
>
>thanks
>


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.