[stringtemplate-interest] StringTemplate and ability to compose a view

Jevgenij [GMail] jevgenij.tsoi at gmail.com
Fri Jan 14 06:22:34 PST 2011


Terence,

Thank you for your feedback, I can see your point, this would be
"stretching" the strict MVC separation.

One way, I suppose we could do it, is to introduce another layer of
abstraction in the model, so the model will include the data for the
menu, and the template would render it iff it was available.
The bad points with this approach would be duplication of logic,
if(menu){} would be both in the model and the view.

Also, if I would happen to have any dynamic data in the header or
footer, the data for the footer and header would need to come from the
model. (In some way the model would have to be aware if the header and
footer is shown or not.)

What I like about ST is that is provides both inheritance and
composition for producing views. But it seems, for composition we need
to duplicate the composition logic. (In model and view, or controller)

Am I getting this backwards? I think I am looking for a good system to
achieve composition of websites of smaller reusable units, without
duplication of composition logic.

Maybe we can discuss an example: A site that supports 2 different
target platforms: mobile and desktop.
The Controller identifies the target platform, executes the model
logic, and delegates data to the platform specific view.
For the desktop version we want a rich header, but no header for the
mobile version. (Or other elements)
What would you suggest for this use case? (Maybe a tutorial I might
have overlooked.)

Thank you for your time,
with regards,
JT

2011/1/14 Terence Parr <parrt at cs.usfca.edu>:
> Hi. Asking the template to delegate control back to the controller makes the template part of the program, in my view, so probably not a good idea. The way I look at things, you push a button dated the templates, and then they render. done.  So, you can apply the menu box template to some data or simply include it, but you can't ask the model to start up again per se. Now, you could pass in an object whose toString method is the menu box [bad] ;)
>
> Ter
>
> On Jan 13, 2011, at 9:25 AM, Jevgenij [GMail] wrote:
>
>> Greetings,
>> We have been looking at different templating engines and ST is one of
>> the most pure and very interesting.
>> Going from an jsp-spaghetti-hell, ST feels like a breath of fresh air.
>>
>> We have an interesting use case, which I am unable to find a way to
>> implement in ST:
>> A html use case, the view looks something like this:
>> <body>
>> <jsp:include page="servlet?action=showMenu" flush="true" />
>> <!-- Render main content -->
>> </body>
>>
>> The interesting bit is jsp:include call, which goes back to the
>> controller, the controller then produces output for the menu.
>> The output is dynamic, with request specific logic, (locale,
>> authentication, etc....)
>>
>> I was trying to find in ST something like a "macro" call, that would
>> delegate control back to the controller,
>> but was unable to find it. Something in the lines of $#MenuBox()$
>> invokes: class MenuBox implements STMacro.
>>
>> Maybe we are approaching this from the wrong angle.
>>
>> How would you implement something equivalent in ST?
>>
>> Regards,
>> JT
>> _______________________________________________
>> 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