[stringtemplate-interest] Simple example of list iteration

Richard Apodaca rapodaca at metamolecular.com
Wed Feb 29 09:21:51 PST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120229/618e0fcc/attachment.html 


More information about the stringtemplate-interest mailing list