[stringtemplate-interest] Does StringTemplate support components?
Nate
misc at n4te.com
Thu Dec 21 14:12:38 PST 2006
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
>
More information about the stringtemplate-interest
mailing list