You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Gary Bisaga <ga...@maximus.com> on 2002/02/04 23:25:40 UTC
Question about dynamically setting template location
I'm not sure if this question would be for the Velocity list or the Turbine
list. I want to have the system look in several different locations for its
templates. Now, I know you can set file.resource.loader.path and have it
look in multiple places.
But the hitch is I want to set the list of paths differently on a
per-request basis. That is, there is something in the request URL (or
possibly the session) that indicates the set of template paths to use. For
example:
- For the URL http://host/app/servlet/app/portal/public, I might want to
look first under /templates/public for the template, then if it's not found
look under /templates/common
- The URL http://host/app/servlet/app/portal/local, however, would result in
looking first under /templates/local then under /templates/common.
I looked at doing something to Velocity's FileResourceLoader, but that
appears to be handled pretty statically; I don't see anything to be able to
change this path on a request-by-request basis. Another possibility would be
to modify the layout to find the templates and then pass the full name to
Velocity (e.g. /templates/public/templatename.vm), perhaps by scanning over
them at startup time and putting the results into a table for easy access. I
guess my questions are (a) does anything handle this already and (b) if not
does my proposed solution sound reasonable.
Thanks,
<>< gary
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Question about dynamically setting template location
Posted by Peter Lynch <pe...@mindspring.com>.
Gary,
I achieve something like you suggest using a number of different techniques.
To answer your (a) question, basically Turbine allows you to do pretty much
whatever as long as you are willing to invest some time coding it. Other
than the resource loader path you found already there is nothing in Turbine
that allows for what you want to do on a per request basis by configuration.
For (b) here are some ideas - I have used all of them before in Turbine 2.1:
- Modify what is in TurbineTemplateService.java . Have fun with this one as
I say it is one of the nastiest pieces in Turbine. Point to your new service
class via turbine.properties.
- Use your build tool to put same named custom templates in different root
directories, allowing any custom templates to override the default ones. I
use a portal type app that needs to support different deployments in the
same web app, and this proved a useful approach to the problem of serving
custom templates. It has the advantage of minimizing the amount of changes
made to the template path requested during runtime.
- Extend the various DynamicURL related classes and pull tools (TemplateLink
et all) to build URLs with a custom path based on some property
-Modify the base module classes VelocityScreen, DefaultScreen,
TemplateScreen, etc. to handle the lookup you suggest. (Although this will
likely need some work with TurbineTemplateService above)
Any way you slice it there is some work involved. Thankfully, Turbine at
least allows you to do the work.
Hope this helps the thinking process...
-Peter
----- Original Message -----
From: "Gary Bisaga" <ga...@maximus.com>
To: "Turbine Users List" <tu...@jakarta.apache.org>
Sent: Monday, February 04, 2002 2:25 PM
Subject: Question about dynamically setting template location
> I'm not sure if this question would be for the Velocity list or the
Turbine
> list. I want to have the system look in several different locations for
its
> templates. Now, I know you can set file.resource.loader.path and have it
> look in multiple places.
>
> But the hitch is I want to set the list of paths differently on a
> per-request basis. That is, there is something in the request URL (or
> possibly the session) that indicates the set of template paths to use. For
> example:
> - For the URL http://host/app/servlet/app/portal/public, I might want to
> look first under /templates/public for the template, then if it's not
found
> look under /templates/common
> - The URL http://host/app/servlet/app/portal/local, however, would result
in
> looking first under /templates/local then under /templates/common.
>
> I looked at doing something to Velocity's FileResourceLoader, but that
> appears to be handled pretty statically; I don't see anything to be able
to
> change this path on a request-by-request basis. Another possibility would
be
> to modify the layout to find the templates and then pass the full name to
> Velocity (e.g. /templates/public/templatename.vm), perhaps by scanning
over
> them at startup time and putting the results into a table for easy access.
I
> guess my questions are (a) does anything handle this already and (b) if
not
> does my proposed solution sound reasonable.
>
> Thanks,
> <>< gary
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>