There are several ways to solve this.

1. With the simple #if contstruct as presented in this
   thread:
#if (! $this)
 #set ($this = 'Velocity')
#end
$this is great!

2. With a macro:
#macro( valueOrDefault $value $default )##
#set( $localValue = $value )## this is accesses $value only once!
#if(!$localValue)$localValue#else$default#end##
#end
...
#valueOrDefault($this, "Velocity") is great!

3. Do the same as the macro with a tool - there was one either
   in the contributions area (or in Turbine) with an isNull()
   allowing a default:
$tool.valueOrDefault($this, "Velocity") is great!

4. The most powerful and implicit solution is to create
   your own context implementation, that takes the value from
   the background ChainedContext if it is defined.
   Look at the implemetnation of the AbstractContext:
http://jakarta.apache.org/velocity/docs/api/org/apache/velocity/context/AbstractContext.html
   -> Creating a read-only context, it would do exaclty
   what you expect.

Cheers,
Christoph

Smith, Mike H wrote:
Hi,

Is there a way to modify the precedence logic of the template engine?

In particular, I'd like to:

1.      Define a template like:

#set( $this = "Velocity")

$this is great!

2.      Within the application code, set the "this" property to be
something different (e.g. "Laughter")
3.      Then have the engine render as "Laughter is great"

With the current implementation the rendering precedence is template
then context, any easy way to reverse this?

Thanks.

Mike



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to