You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Adam Flynn <af...@mrcuk.com> on 2005/11/02 18:12:43 UTC

Escaping VTL References

OK. Let's say I want to output ${madeup} as a literal in my template.
All I need to do is prefix a backslash and I'm done right? Maybe not.
Consider the following.

Let's say appId is in the velocity context and is equal to i00010. Let's
also say madeup isn't in the velocity context. The following template
snippet...

${appId}
\${appId}
${madeup}
\${madeup}

...will produce the following output...

i00010
${appId}
${madeup}
\${madeup}

But this is wrong, surely? What happens if I use a context that *does*
contain madeup. I just want to output the literal ${madeup} (for example,
because I am producing a JSTL page, or another velocity file): the contents
of the context should be irrelevant.

Am I missing something here? The alternative is that I use some sort of
naming convention to avoid this situation.

Thanks in advance,
	





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


RE: Escaping VTL References

Posted by Adam Flynn <af...@mrcuk.com>.
Thanks. That does the trick.

-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: 02 November 2005 17:36
To: Velocity Users List
Subject: Re: Escaping VTL References

Backslash can't be relied on.

Use

#set($d = '$')
${d}{madeup}

You can also use ${esc.d} instead of ${d} if you have the escape tool
in your template.


On 11/2/05, Adam Flynn <af...@mrcuk.com> wrote:
> OK. Let's say I want to output ${madeup} as a literal in my template.
> All I need to do is prefix a backslash and I'm done right? Maybe not.
> Consider the following.
>
> Let's say appId is in the velocity context and is equal to i00010. Let's
> also say madeup isn't in the velocity context. The following template
> snippet...
>
> ${appId}
> \${appId}
> ${madeup}
> \${madeup}
>
> ...will produce the following output...
>
> i00010
> ${appId}
> ${madeup}
> \${madeup}
>
> But this is wrong, surely? What happens if I use a context that *does*
> contain madeup. I just want to output the literal ${madeup} (for example,
> because I am producing a JSTL page, or another velocity file): the
contents
> of the context should be irrelevant.
>
> Am I missing something here? The alternative is that I use some sort of
> naming convention to avoid this situation.
>
> Thanks in advance,
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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


Re: Escaping VTL References

Posted by Mike Kienenberger <mk...@gmail.com>.
Backslash can't be relied on.

Use

#set($d = '$')
${d}{madeup}

You can also use ${esc.d} instead of ${d} if you have the escape tool
in your template.


On 11/2/05, Adam Flynn <af...@mrcuk.com> wrote:
> OK. Let's say I want to output ${madeup} as a literal in my template.
> All I need to do is prefix a backslash and I'm done right? Maybe not.
> Consider the following.
>
> Let's say appId is in the velocity context and is equal to i00010. Let's
> also say madeup isn't in the velocity context. The following template
> snippet...
>
> ${appId}
> \${appId}
> ${madeup}
> \${madeup}
>
> ...will produce the following output...
>
> i00010
> ${appId}
> ${madeup}
> \${madeup}
>
> But this is wrong, surely? What happens if I use a context that *does*
> contain madeup. I just want to output the literal ${madeup} (for example,
> because I am producing a JSTL page, or another velocity file): the contents
> of the context should be irrelevant.
>
> Am I missing something here? The alternative is that I use some sort of
> naming convention to avoid this situation.
>
> Thanks in advance,
>
>
>
>
>
>
> ---------------------------------------------------------------------
> 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