velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: Subclassing VelocityLayoutServlet?
Date Thu, 18 Oct 2007 19:38:59 GMT
The standard method for making variables available to all templates is
via the Toolbox support.

If these variables are simple values (String, Number, or Boolean),
then i'd recommend putting them in your toolbox.xml as data elements.
If they are more complicated types, consider whether the classes
needed can be used as tools or retrieved from a custom tool.

If they can't be provided directly from the toolbox as either a tool
or data, and you want them to be directly available (as $myvar instead
of $myvartool.myvar), then you should override the createContext(...)
method in a subclass of the VelocityLayoutServlet like this:

protected Context createContext(HttpServletRequest request,
HttpServletResponse response) {
        Context ctx = super.createContext(request, response);
        //TODO: add your global vars here
        return ctx;
}

On 10/18/07, White, Tim <Tim.White@qwest.com> wrote:
> Hi there -
>
>  What's the recommended way to extend the VelocityLayoutServlet such
> that certain things happen on every call?
>
>  Specficially, I need to set a number of variables every time so that
> they are globally available to every template.
>
> Thanks!
>
> Tim
>
>
> This communication is the property of Qwest and may contain confidential or
> privileged information. Unauthorized use of this communication is strictly
> prohibited and may be unlawful.  If you have received this communication
> in error, please immediately notify the sender by reply e-mail and destroy
> all copies of the communication and any attachments.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message