Re: Calling macro with tricky parameter name

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, February 22, 2012, 4:21:31 PM, Jerker Klang wrote:

> Hello all,
>
> I have a macro that I want to use for producing html5 page (fragments).
> It looks like this:
>
> <#macro input id params...>
> <#list params?keys as param>
>      Key: ${param}<br />
>      Value: ${params[param]}<br />
> </#list>
> </#macro>
>
> Question: How do I call that macro with parameter named data-custom with
> the value freemarker?

As far as I see, you just can't do that. You will have to use '_'
instead, and then ?replace('_', '-') it where you print it. /-:

> The naive aproach would have been:
>
> <@input id="something" data-custom="freemarker" />
>
> Background:
> In html5 they have the new convention that you can enter custom data 
> attributes  on elements by using a data- prefix on all attributes. I 
> suspect that my question is likely to reoccur in the future as html5 
> becomes more common.

Yeah... it should be improved in the parser. Except, it can't be done
in a backward-compatible way. <@foo 'data-bar'=1 /> means
<@foo 'data-bar' == 1 />, since for whatever reason '=' is an alias to
'=='.

> I've browsed through the FAQ and .vars in mentioned for accessing the 
> variables but that isn't a problem me (since I'm iterating through params).
>
> Is there a way to specify a tricky parameter name somehow?
>
> Thanks in advance!
>
> //Jerker
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing 
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
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.