How to modify macro paramater value and send it to another macro ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to modify macro paramater value and send it to another macro ?

Albert Kam
I would like to pass a hash to a macro, modify the hash's sequence value within the macro, and then pass the modified hash to another macro.

I have put on a simple example to illustrate with 'non' freemarker comments :

// try to add 'java' to plugins.tools sequence and pass it to @print
// but still the plugins passed to @print doesnt contain 'java'
<#macro printAndModify plugins>
${plugins.project} uses <@printList plugins.tools />
<#local tools=plugins.tools
tools=tools + ['java']
'plugins.tools'=tools>
<@print plugins />
</#macro>

<#macro print plugins>
${plugins.project} uses <@printList plugins.tools />
</#macro>

<#macro printList list>
<#list list as item>${item} </#list>
</#macro>

<#assign plugins={'project' : 'cool project', 'tools' : ['freemarker']}>

<@printAndModify plugins />


The output of the project is :

cool project uses freemarker 

cool project uses freemarker 


The expected output is :

cool project uses freemarker 

cool project uses freemarker java 

Is there anyway to do this in the ftl ? Thank you.

--
Do not pursue the past. Do not lose yourself in the future.
The past no longer is. The future has not yet come.
Looking deeply at life as it is in the very here and now,
the practitioner dwells in stability and freedom.
(Thich Nhat Hanh)

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|

Re: How to modify macro paramater value and send it to another macro ?

Daniel Dekany
Sunday, July 28, 2013, 6:24:39 PM, Albert Kam wrote:

> I would like to pass a hash to a macro, modify the hash's sequence
> value within the macro, and then pass the modified hash to another macro.
>
> I have put on a simple example to illustrate with 'non' freemarker comments :
>
> // try to add 'java' to plugins.tools sequence and pass it to @print
> // but still the plugins passed to @print doesnt contain 'java'
> <#macro printAndModify plugins>
>  ${plugins.project} uses <@printList plugins.tools />
>  <#local tools=plugins.tools
>   tools=tools + ['java']
>   'plugins.tools'=tools>
>  
>  <@print plugins />
> </#macro>

<#local 'plugins.tools'=tools> just creates a local variable called
"plugins.tools".

You can do this like:

<#macro printAndModify plugins>
 ${plugins.project} uses <@printList plugins.tools />
 <@print plugins + { 'tools': plugins.tools + ['java'] } />
</#macro>

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user