Albert Kam
2013-07-28 16:24:39 UTC
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.
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)
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)