[stringtemplate-interest] Simple example of list iteration
Terence Parr
parrt at cs.usfca.edu
Wed Feb 29 11:27:13 PST 2012
in v4 there is no implicit it. That means you can simply declare it and it will work:
> $items:{it | <li>$it$</li>}$
please try that, though it sounds like there may be something else going on.
Ter
On Feb 29, 2012, at 9:21 AM, Richard Apodaca wrote:
> I'm new to StringTemplate and baffled about how to iterate over a list using ST4 in a servlet.
>
> Given a List<String> called "items":
>
> List<String> items = Arrays.asList("hello", "world");
> view.set("items", items);
>
> I've seen examples claiming this works:
>
> <ul>
> $items:{<li>$it$</li>}$
> </ul>
>
> But I get this error:
>
> > anonymous template has 0 arg(s) but mapped across 1 value(s)
>
> which was discussed here:
>
> http://www.antlr.org/pipermail/stringtemplate-interest/2011-February/003064.html
>
> Trying the different form suggested above (which I could be misinterpreting):
>
> $items:{value|$value$}$
>
> gives this error:
>
> > no such template: /layouts/_sub20
>
> I'm setting up the template via the servlet with:
>
> STRawGroupDir dir = new STRawGroupDir("/com/foo/views", '$', '$');
> ST template = dir.getInstanceOf("layouts/application");
>
> The "_sub{x}" part in the error increases every time I try to reload my page. Any ideas of where this simple thing is going wrong?
>
> Thanks,
> Rich
>
> --
> Richard L. Apodaca
> Founder and CEO
> Metamolecular, LLC
> 8070 La Jolla Shores Drive #464
> La Jolla, CA 92037
> 858.658.0860
>
> http://metamolecular.com
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list