[stringtemplate-interest] Maps without pre-defined keys
Terence Parr
parrt at cs.usfca.edu
Sat May 19 15:34:08 PDT 2007
On May 19, 2007, at 7:10 AM, Vinod Singh wrote:
> Thanks, Terence I got it working. Now I am facing another problem-
>
> I have a map like-
> Map<String, List> map;
>
> and passing it to template-
> template.setAttribute("tabs", map);
>
> Iterating over keys and corresponding List inside template-
> <tabs.keys:{k| <tabs.(k):layoutTab(panel="panelName");
> separator="\n">}; separator="\n">
>
> in turn accessing another sub-template-
> layoutTab( panel) ::= <<
> <it.screenField:layout (...)>
> >>
That '...' as arg will allow panel to flow through, but the arg on
layout still hides the previous version. Manual portion:
> When building code generators with StringTemplate, large heavily
> nested template tree structures are commonplace and, due to dynamic
> attribute scoping, a nested template could inadvertently use an
> attribute from an enclosing scope. This could lead to infinite
> recursion during rendering and other surprises. To prevent this,
> formal arguments on template t hide any attribute value with that
> name in any enclosing scope. Here is a test case that illustrates the
> point.
remove the arg to layout or simply say layout(name=name)
I hope that works. ;)
Ter
More information about the stringtemplate-interest
mailing list