Quantcast

Newbie question: using variable names to access sub-hashes in data model

Previous Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Newbie question: using variable names to access sub-hashes in data model

YoavShapira
Hi,
Please forgive my ignorance on this: I've read the FAQ and manual,
searched the mailing list archives, and found what looks to be
applicable help on this topic, but I still can't get this to work.

I have a data model along these lines:
Map root = new HashMap();
Map level1 = new HashMap();
root.put("level1key", level1);
Map level2 = new HashMap();
level1.put("level2key", level2);

I'd like to be able to loop over this model in a nested #list using
the loop variable for the outloop as the key for the inner loop, e.g.
<#list level1?keys as level1key>
  <#list root["level1key]"?values as level2value>
    <li>${level1value} - ${level2value}</li>
  </#list>
</#list>

Unfortunately Freemarker complains about the second #list line saying
"level1key" is not a variable.  If I try ${level1key} it complains
about the syntax saying it was expecting another character, not a {.

I'm using Freemarker 2.3.8 on Java 1.5.0_07, Windows XP.

Thanks for your help and patience, I did try to research this but just
can't get it to work ;)

Yoav

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Newbie question: using variable names to access sub-hashes in data model

Daniel Dekany
Friday, August 11, 2006, 3:58:16 PM, Yoav Shapira wrote:

> Hi,
> Please forgive my ignorance on this: I've read the FAQ and manual,
> searched the mailing list archives, and found what looks to be
> applicable help on this topic, but I still can't get this to work.
>
> I have a data model along these lines:
> Map root = new HashMap();
> Map level1 = new HashMap();
> root.put("level1key", level1);
> Map level2 = new HashMap();
> level1.put("level2key", level2);
>
> I'd like to be able to loop over this model in a nested #list using
> the loop variable for the outloop as the key for the inner loop, e.g.
> <#list level1?keys as level1key>
>   <#list root["level1key]"?values as level2value>
>     <li>${level1value} - ${level2value}</li>
>   </#list>
> </#list>
>
> Unfortunately Freemarker complains about the second #list line saying
> "level1key" is not a variable.

Your example contains numerous mistakes, like you didn't added a
"root" variable to you model, yet you write root[...] in the template,
then the closing ] and the closing " is exchanged in the 2nd <#list ...>
tag, and then you didn't assigned value to level1value anywhere, yet you
refer to it inside the <li>. So I'm not sure what you wanted, but note
that if you write root[level1key] (note: no quotation marks), then it
means: Get the value from the "root" map, whose key equals to the
value of the "level1key" variable. Maybe that was one of the things
that you wanted.

> If I try ${level1key} it complains
> about the syntax saying it was expecting another character, not a {.
>
> I'm using Freemarker 2.3.8 on Java 1.5.0_07, Windows XP.
>
> Thanks for your help and patience, I did try to research this but just
> can't get it to work ;)
>
> Yoav

--
Best regards,
 Daniel Dekany


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Newbie question: using variable names to access sub-hashes in data model

YoavShapira
Daniel,
Thank you for your help.  I figured it out ;)

Yoav

On 8/11/06, Daniel Dekany <[hidden email]> wrote:

> Friday, August 11, 2006, 3:58:16 PM, Yoav Shapira wrote:
>
> > Hi,
> > Please forgive my ignorance on this: I've read the FAQ and manual,
> > searched the mailing list archives, and found what looks to be
> > applicable help on this topic, but I still can't get this to work.
> >
> > I have a data model along these lines:
> > Map root = new HashMap();
> > Map level1 = new HashMap();
> > root.put("level1key", level1);
> > Map level2 = new HashMap();
> > level1.put("level2key", level2);
> >
> > I'd like to be able to loop over this model in a nested #list using
> > the loop variable for the outloop as the key for the inner loop, e.g.
> > <#list level1?keys as level1key>
> >   <#list root["level1key]"?values as level2value>
> >     <li>${level1value} - ${level2value}</li>
> >   </#list>
> > </#list>
> >
> > Unfortunately Freemarker complains about the second #list line saying
> > "level1key" is not a variable.
>
> Your example contains numerous mistakes, like you didn't added a
> "root" variable to you model, yet you write root[...] in the template,
> then the closing ] and the closing " is exchanged in the 2nd <#list ...>
> tag, and then you didn't assigned value to level1value anywhere, yet you
> refer to it inside the <li>. So I'm not sure what you wanted, but note
> that if you write root[level1key] (note: no quotation marks), then it
> means: Get the value from the "root" map, whose key equals to the
> value of the "level1key" variable. Maybe that was one of the things
> that you wanted.
>
> > If I try ${level1key} it complains
> > about the syntax saying it was expecting another character, not a {.
> >
> > I'm using Freemarker 2.3.8 on Java 1.5.0_07, Windows XP.
> >
> > Thanks for your help and patience, I did try to research this but just
> > can't get it to work ;)
> >
> > Yoav
>
> --
> Best regards,
>  Daniel Dekany
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...