Dynamic interpolation names

Andrew Moore <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hi,
I'm trying to display a list of data to the screen where each of the
elements has a unique number
for example i've done: 
   root.put('menu1','details here');
   root.put('menu2','details here');
   root.put('menu3','details here');

When it comes to displaying details in the freemarker template, I'm then
writing out the data with something like this:
      <#if menu1??> DO LOTS HERE</#if>
      <#if menu2??> DO LOTS HERE</#if>
      <#if menu3??> DO LOTS HERE</#if>

I know it's not very nice because there's lots of repeating code, so I'd
though of doing it as a macro.
What I'd like is something like
   <@listMenu menuNumber="1">
   <@listMenu menuNumber="2">
   <@listMenu menuNumber="3">

    <#macro listMenu menuNumber>
          <#if menu!MENUNUMBER!??> DO LOTS HERE</#if>
    </#macro>

where !MENUNUMBER! is the value passed into the parameter.

But I'm not sure what syntax I should use. I've done macros where values
have been passed in and used within the macro, but not where they form part
of the name of the interpolation. Is there any way I can dynamically
reference interpolation names?

Hope that makes some sense!

If there's a better way to do it also, that would be great, but due to the
design of the system (that's not under my control) I'm stuck with menu1,
menu2, menu3 etc instead of having a list.

Thanks
Andrew 


-- 
View this message in context: http://www.nabble.com/Dynamic-interpolation-names-tp15357158p15357158.html
Sent from the freemarker-user mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
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.