[stringtemplate-interest] Simple example of list iteration
Richard Apodaca
rapodaca at metamolecular.com
Wed Feb 29 11:15:05 PST 2012
To follow up with something easier to test/debug - here's a complete JUnit
test that shows the source of my confusion:
https://gist.github.com/1943633
The first test passes as I expect. The second test gives the error:
context [template] 1:1 no such template: /_sub1
context [template] 1:8 passed 1 arg(s) to template null with 0 declared
arg(s)
context [template] 1:1 passed 1 arg(s) to template null with 0 declared
arg(s)
context [template] 1:1 passed 1 arg(s) to template null with 0 declared
arg(s)
context [template] 1:1 passed 1 arg(s) to template null with 0 declared
arg(s)
Any ideas?
Thanks,
Rich
On Wed, Feb 29, 2012 at 9:21 AM, Richard Apodaca <rapodaca at metamolecular.com
> 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
>
>
--
Richard L. Apodaca
Founder and CEO
Metamolecular, LLC
8070 La Jolla Shores Drive #464
La Jolla, CA 92037
858.658.0860
http://metamolecular.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120229/9641a4f7/attachment.html
More information about the stringtemplate-interest
mailing list