[stringtemplate-interest] Does StringTemplate support components?
Adam Bennett
adamb at videx.com
Thu Dec 21 15:55:19 PST 2006
Please be aware that I have zero practical experience with StringTemplate. I am just researching its viability for our web application refactoring project. From the documentation I gather that StringTemplate readily supports templates including other templates ("Template references" is the term used). That is not the problem. The problem is that I want the referenced template to be completely independent. This means that I need a hook to supply the referenced template with the parameters it needs to render. _____
From: Nate [mailto:misc at n4te.com]
To: Adam Bennett [mailto:adamb at videx.com]
Cc: stringtemplate-interest at antlr.org
Sent: Thu, 21 Dec 2006 14:12:38 -0800
Subject: Re: [stringtemplate-interest] Does StringTemplate support components?
Why not give the parent template an attribute "forumUserBox" that is the
configured StringTemplate it needs to use. Then I believe
$forumUserBox()$ executes the configured template. If not you could do a
toString on the template and set "forumUserBox" to that. Then use
$forumUserBox$ in your parent template.
-Nate
Adam Bennett wrote:
> Can I use StringTemplate to create reusable components as can be done with JSP tags?
>
> For example, let's say I want a component that shows a user summary box like you would see beside each users post on an online forum. The component would use a StringTemplate to generate markup to show the users alias, image, and number of posts. This formUserBox template would take these values as parameters but first I need some Java code to look at the session and pull the correct values out of the database.
>
> So here I have a parent template that invokes the forumUserBox template:
>
> <html>
> <body>
> ...
> $forumUserBox()$
> ...
> </body>
> </html>
>
> But forumUserBox needs attributes that have not been set. The code that invokes the parent template should not have to worry about providing all the necessary parameters - (separation of concerns).
>
> Custom JSP tags allow me to do this but they are inside out. Is my desire "unclean"? It does not seem so to me because the view and model are still clearly separated by using a parameterized StringTemplate to generate the actual markup. What I need is some sort of processing hook. Before the parent template invokes the forumUserBox template I need it to call some java code so I can provide the necessary attributes.
>
> Thanks much.
> - Adam B
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061221/e53300af/attachment.html
More information about the stringtemplate-interest
mailing list