FAQ

I'm almost considering overriding the VLS and adding my variable to the
velocity context. Maybe later though. :)
It's a common practice for such needs.
For instance, you can override the createContext( ) method and add your custom variables to the context you get from
super.createContext( ).

CloD

----- Original Message -----
From: "Charles N. Harvey III" <charlieh@alloy.com>
To: "Velocity Users List" <velocity-user@jakarta.apache.org>
Sent: Friday, July 16, 2004 6:56 PM
Subject: Re: setting variables with VelocityLayoutServlet

The $screen_content is processed first, right. I knew that too because
I often set variables in the screen that I then access from my "wrapper".
But this time I need a variable available in lots of screens and I don't
want to have to set it in all of them. And, its not one of them static
variables. We have a setting in our tomcat servers that tells the app
which server it is on (development, staging, production). On each server
some things change. So I want my $server to be available to all the
screens and layouts.

Looks like it ain't gonna work exactly the way I want it to. Which is ok.
The more I look at the code, its really only about 10 screens that need
the variable so I can call a macro from each of them.

I'm almost considering overriding the VLS and adding my variable to the
velocity context. Maybe later though. :)


Charlie



Nathan Bubna said the following on 7/16/2004 12:48 PM:
Charles N. Harvey III said:

I was wondering about setting global variables in my templates when
I am using the VVS. If I do a #set( $myVar = "thing" ) in my layout.vm
page, that variable does not show up in the page that is called up in
the $screen_content. Is there a way to do this? Is there a #global
directive?
layout.vm? $screen_content? it sounds like you're using the VLS, not the
VVS. :)

the thing to remember about the VelocityLayoutServlet is that the screen
template ($screen_content) is processed first. so anything that it sets in
the context is available to the layout template, but not vice versa. anything
that happens in the layout template happens after the screen processing is
already over. so the simple answer is "no."

however, it is possible (and quite easy) to make variables available to both
layout and screen before either of them is processed, because anything made
available to the screen is available to the layout as well.

and there's always the application-wide way to specify global variables in the
toolbox:

<data type="string">
<key>myVar</key>
<value>thing</key>
</data>

Nathan Bubna
nathan@esha.com


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



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

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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 7 | next ›
Discussion Overview
groupuser @
categoriesvelocity
postedJul 16, '04 at 3:27p
activeJul 16, '04 at 6:09p
posts7
users4
websitevelocity.apache.org

People

Translate

site design / logo © 2021 Grokbase