You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Marc Logemann <de...@logemann.info> on 2002/06/26 11:55:20 UTC

easy way to load templates from webapp relative folders

Hi,

i am just checking how to retrieve template from a path relative
to webapp, in my case /webapp/Web-inf/templates

Of course it would be nice to have such a resource loader which can
be configurated through velocity.properties, but when i look at exampleservlet2,
there is an override of loadConfiguration() in order to achieve this.

Can someone tell me how to achieve this in the best way?


---
greetings from
Marc Logemann
Homebase @ www.logemann.info


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: easy way to load templates from webapp relative folders

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On 6/26/02 5:55 AM, "Marc Logemann" <de...@logemann.info> wrote:

> Hi,
> 
> i am just checking how to retrieve template from a path relative
> to webapp, in my case /webapp/Web-inf/templates
> 
> Of course it would be nice to have such a resource loader which can
> be configurated through velocity.properties, but when i look at
> exampleservlet2,
> there is an override of loadConfiguration() in order to achieve this.
> 
> Can someone tell me how to achieve this in the best way?
> 

The way I do it is use the file resource loader, set my path to be
/WEB-INF/templates, and then in my init(), munge the path via

           String root = getServletContext().getRealPath(value);

Before setting the property

           ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, root);

In the vel config.  Is this the best way?  Dunno.

Another approach I use is the WebappLoader from velocity-tools/view which
has a configuration requirement in init like :

   ServletAppContext vssac = new ServletAppContext(getServletContext());
   ve.setApplicationAttribute( WebappLoader.ATTRIBUTE_KEY, vssac);

But also makes life easy.

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>