Re: how to use a nested value as the input to an "inner macro"?

Daniel Dekany <[email protected]> Tue, 9 Sep 2003 10:41:16 +0200
Newsgroups gmane.comp.text.fmpp
Message-ID <[email protected]>
Monday, September 8, 2003, 4:02:49 PM, Ralf Hauser wrote:

> Hi,
>
> First I thought I had misspelled <#nested>
> (http://sourceforge.net/tracker/index.php?func=detail&aid=802412&group_id=79
> 4&atid=100794), but perhaps I am trying something a little bit too
> sophisticated.
> Unfortunately, the documentation doesn't give an example for how to do this
> (http://www.freemarker.org/docs/ref_directive_macro.html).
>
> The following attempts all failed:
>
> <#macro outerMacro>
> <@innerMacro param1="<#nested>" /></#macro>
>
> <@outerMacro>helloWorld</@outerMacro>
>
> unfortunately results in "<#nested"> instead of helloWorld

The documentation does say something about this, just not directly: it
should be clean from the syntax description that you can't use
directives (not just "nested") in string literals, or inside FTL tags
anyway. Well, I will state this more explicitly in
dgui_template_overallstructure.html.

> other attempts wouldn't even pass fmpp:
> <#macro outerMacro>
> <@innerMacro param1=<#nested> /></#macro>

Yeah, this is syntactically bad, as <#nested> is not a valid expression.

> <#macro outerMacro>
> <@innerMacro param1=nested /></#macro>

This wants to pass the value of variable called "nested", so of course
it will not do what you want.

> any hints would be highly appreciated!

The solution is to call the directive, and capture its output into a
string variable, and then use that string as the parameter:

<#macro outerMacro>
  <#local x><#nested></#local>
  <@innerMacro param1=x />
</#macro>

-- 
Best regards,
 Daniel Dekany




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf