You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Paul Kmiec <km...@expertcity.com> on 2001/10/11 05:16:25 UTC

Escaping rules

Hello,
  
I've looked through the mailing list archive and the online docs and
couldn't quite find an answer to my question. I think Velocity is very
nice except for its escaping rules. 

I don't understand why treatment of \$myVar is different depending on
whether the myVar is defined or not. If I want a template to render as
'the $myVar is something used', I can't just write 'the \$myVar is
sometimes used'. For each such usage, it seems I have to have an if
statement to check if the variable is actually defined or not. 

There is another example in the user guide that I also find
weird. It says that if the template contains,
\#if ( $jazz )
  Vyacheslav Ganelin
\#end
it will render as
#if ( $jazz ) Vyacheslav Ganelin #end

I was rather expecting,

#if ( <$jazz> )
  Vyacheslav Ganelin
#end 

In fact, how would one achieve this output?

Thanks,
Paul


Re: Escaping rules

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/10/01 11:16 PM, "Paul Kmiec" <km...@expertcity.com> wrote:

> Hello,
> 
> I've looked through the mailing list archive and the online docs and
> couldn't quite find an answer to my question. I think Velocity is very
> nice except for its escaping rules.

Heh.

> 
> I don't understand why treatment of \$myVar is different depending on
> whether the myVar is defined or not.

Because $myVar is only a reference if there is something in the context.

I know it appears strange, but that's what makes schmoo into a reference -
existence of a backing object in the context.

> If I want a template to render as
> 'the $myVar is something used', I can't just write 'the \$myVar is
> sometimes used'. For each such usage, it seems I have to have an if
> statement to check if the variable is actually defined or not.

Well, yes.  The idea is that it shouldn't be roulette, I guess.
 
> There is another example in the user guide that I also find
> weird. It says that if the template contains,
> \#if ( $jazz )
> Vyacheslav Ganelin
> \#end
> it will render as
> #if ( $jazz ) Vyacheslav Ganelin #end
> 
> I was rather expecting,
> 
> #if ( <$jazz> )
> Vyacheslav Ganelin
> #end 
> 
> In fact, how would one achieve this output?

I am guessing you didn't try it :)

The user's guide is wrong.  I will go fix....

geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin