[stringtemplate-interest] Newlines and templates applied to multivalued attributes.

Zenaan Harkness zen at freedbms.net
Thu Jul 3 19:15:52 PDT 2008


> I'm having a bit of trouble with newlines (seperators) when I am doing a
> conditional test 
> inside of a template being applied to a multi-valued attribute. I don't
> want a
> newline created if the called template has no output.
> 
> 
> Outertemplate ::= <<
> 
> <listofthings:listitem();separator="\n">
> 
> >>

One way is, in your model (listofthings), to build up the "business
logic" in your model, so that the model provides accessors for
getSubListOfThings() for example. Then your template might become:

   <subListOfThings:listitem();separator="\n">

If you insert a new attribute into your template just for that model, or
as I do it, just insert the model as (one of) my attribute, and access
things like so:

   <model.subListOfThings:listitem();separator="\n">

The model is where you want your logic, your custom data manipulators,
etc.

The philosophy of StringTemplate is _strict_ MVC. It is in fact the only
strict MVC templating engine on the planet (as far as I ever found)!

This has consequences:

* It requires a new discipline of template and system authoring.

* Anything that starts to get even a little interesting must be
  implemented in your model.

* You get a really clean separation of model and logic, from view code,
  as a result.

I work in Java, so my Model.java class(es) implement my "interesting"
stuff.

Good luck, StringTemplate is a great tool!

zen

-- 
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the stringtemplate-interest mailing list