Another approach is to use Velocity #evaluate directive[1].
properties:
Intro=Hello ${Name}, welcome to the application
Page.java:
addModel("intro", getMessage("Intro"));
addModel("Name", "John");
template.htm:
#evaluate($intro)
bob
[1]:http://velocity.apache.org/engine/releases/velocity-1.6.2/user-guide.html#Evaluate
On 7/22/09, Bob Schellink <[email protected]> wrote:
> Hi Garth,
>
> I've been wondering about this today. The most obvious solution is probably
> to
> use Java's MessageFormat and replace the property variables before adding
> them
> to the model. Off course MessageFormat doesn't support named parameters,
> only
> numeric ones. So you have to use:
>
> Intro=Hello {0}, welcome to the app
>
> Alternatively you might want to look at Velocity Renderable[1] interface.
> Its
> new in 1.6.
>
> Normally Velocity will invoke the toString() method of the variable it finds
> in
> the template. However if the variable implements Renderable, Velocity will
> invoke a callback method which allows you to manipulate the output as
> needed.
>
> I haven't used this Velocity feature yet but it seems quite powerful.
>
> Let us know what solution you end up using.
>
> kind regards
>
> bob
>
> [1]:http://velocity.apache.org/engine/devel/apidocs/org/apache/velocity/runtime/Renderable.html
>
> Garth Dahlstrom wrote:
>> Hi
>> I'm wondering if there is a recommended approach to replacing variables
>> that occur within other variables.
>>
>> I have text which I add to the model that comes from a properties file
>> that looks like:
>> Intro=Hello ${Name}, welcome to the application
>> Name=John
>>
>> I could break up intro into chunks in my template, but that will make
>> things slightly more difficult to maintain, particularily when I send it
>> for translation.
>>
>> So, is there a way to get model-variable subsitution to run a second
>> time or a way for me to change the to-be-rendered output to acomplish
>> something like this?
>>
>> Thanks,
>> -G
>>
>
>
--
http://incubator.apache.org/click/