You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Russell Black <ru...@iarchives.com> on 2003/01/02 05:34:34 UTC

Escaping dots

I have dots in most of application's java.util.Properties, and I construct my VelocityContext using these properties.  This causes problems when I try to include these properties in a template, since dots have special meaning to the velocity template processor.  Is there a way to instruct the template processor to treat the entire string, including dots, as the key into my VelocityContext?  

For example, I'd like to say
Properties p = new Properties();
p.put("my.property","foo");
VelocityContext context= new VelocityContext(p);

and then I'd like to include my.property in a template.  

${my.property} does not work, because it interprets the dot as an indirection.

Is there some way to escape it?

Re: Escaping dots

Posted by Nathan Bubna <na...@esha.com>.
Russell said:
> I have looked in the list archives, and can't find any answers to this
> issue.  If it can't be done, please tell me.
[snip]
> I have dots in most of application's java.util.Properties, and I construct
> my VelocityContext using these properties.  This causes problems when I
try
> to include these properties in a template, since dots have special meaning
> to the velocity template processor.  Is there a way to instruct the
template
> processor to treat the entire string, including dots, as the key into my
> VelocityContext?

well, there isn't any way to escape the dot.  as it is in java, it's an
integral part of the velocity syntax.  the best i can suggest is that you
put a reference to the context into the template and ask that directly for
your properties.  something like this:

Properties p = new Properties();
p.put("my.property","foo");
VelocityContext context = new VelocityContext(p);

// add a self-reference to the context
context.put("ctx", context);

and then in the template, do:

$ctx.get('my.property')

it's not much fun, but it ought to work for you.

Nathan Bubna
nathan@esha.com


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


Re: Escaping dots

Posted by Russell Black <rb...@iarchives.com>.
I have looked in the list archives, and can't find any answers to this
issue.  If it can't be done, please tell me.

Thanks in advance,
Russell

----- Original Message -----
From: "Russell Black" <ru...@iarchives.com>
To: <ve...@jakarta.apache.org>
Sent: Wednesday, January 01, 2003 9:34 PM
Subject: Escaping dots


I have dots in most of application's java.util.Properties, and I construct
my VelocityContext using these properties.  This causes problems when I try
to include these properties in a template, since dots have special meaning
to the velocity template processor.  Is there a way to instruct the template
processor to treat the entire string, including dots, as the key into my
VelocityContext?

For example, I'd like to say
Properties p = new Properties();
p.put("my.property","foo");
VelocityContext context= new VelocityContext(p);

and then I'd like to include my.property in a template.

${my.property} does not work, because it interprets the dot as a
dereference.

Is there some way to escape it?



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