You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tim Chamberlain <tc...@sportingnews.com> on 2001/11/05 23:02:56 UTC

Quick Escaping Question

Hello List,

I have a quick question about escaping characters.  In a template I am 
trying to output #.   If I simply type #, nothing is printed out.  The 
manual talks about escaping $ with \$ but I did not see escaping the 
pound sign anywhere.  I tried the same technique with # (ie \#), but \ 
was printed out instead of the #  I was expecting.  Is it possible to 
escape the pound character?

Thanks in advance,
Tim


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


RE: Quick Escaping Question

Posted by Justin Sampson <js...@covia.com>.
I just happened to try the same thing earlier today and had no problem.

>From what I observed, as long as the # was not followed by an existing
directive (like #if), it was printed out directly. Otherwise, putting a
backslash in front of it escaped it just fine.

This is with Velocity 1.1.

Justin

> -----Original Message-----
> From: Tim Chamberlain [mailto:tchamberlain@sportingnews.com]
> Sent: Monday, November 05, 2001 2:03 PM
> To: velocity-user@jakarta.apache.org
> Subject: Quick Escaping Question
> 
> Hello List,
> 
> I have a quick question about escaping characters.  In a template I am 
> trying to output #.   If I simply type #, nothing is printed out.  The 
> manual talks about escaping $ with \$ but I did not see escaping the 
> pound sign anywhere.  I tried the same technique with # (ie \#), but \ 
> was printed out instead of the #  I was expecting.  Is it possible to 
> escape the pound character?
> 
> Thanks in advance,
> Tim
> 
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>


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


Re: Quick Escaping Question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/6/01 11:54 AM, "Tim Chamberlain" <tc...@sportingnews.com>
wrote:

> Hello again,
> 
> Im still having the same problem trying to print a #.
> I have tried to accomplish this with the following lines of code:
> 
> <td align=center class=v10><b>#</b></td>
> <td align=center class=v10><b> # </b></td>
> <td align=center class=v10><b>\#</b></td>
> 
> The first two render nothing and the third gives me a \.
> 
> The same thing happens if I replace the # with a $.  I am trying to do
> this within a #if statement within a #macro using version 1.2, if that
> makes any difference.
> Any thougths?


Fixed.  Use latest CVS or wait for tonight's nightly....

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


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


Re: Quick Escaping Question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/6/01 11:54 AM, "Tim Chamberlain" <tc...@sportingnews.com>
wrote:

> Hello again,
> 
> Im still having the same problem trying to print a #.
> I have tried to accomplish this with the following lines of code:
> 
> <td align=center class=v10><b>#</b></td>
> <td align=center class=v10><b> # </b></td>
> <td align=center class=v10><b>\#</b></td>
> 
> The first two render nothing and the third gives me a \.
> 
> The same thing happens if I replace the # with a $.  I am trying to do
> this within a #if statement within a #macro using version 1.2, if that
> makes any difference.
> Any thougths?


Yep, I see it.

Thanks.  Do the #set() workaround until I fix.  Should be quick.  Sorry
about this.

Geir
 
> Thanks again,
> Tim
> 
> Geir Magnusson Jr. wrote:
> 
>> On 11/5/01 5:02 PM, "Tim Chamberlain" <tc...@sportingnews.com> wrote:
>> 
>>> Hello List,
>>> 
>>> I have a quick question about escaping characters.  In a template I am
>>> trying to output #.   If I simply type #, nothing is printed out.
>>> 
>> 
>> A # should be printed out.  What version of velocity are you using?
>> 
>>> The 
>>> manual talks about escaping $ with \$ but I did not see escaping the
>>> pound sign anywhere.  I tried the same technique with # (ie \#), but \
>>> was printed out instead of the #  I was expecting.  Is it possible to
>>> escape the pound character?
>>> 
>>> Thanks in advance,
>>> Tim
>>> 
>> 
>> You only need to escape #<token> when <token> is a valid directive, like
>> 
>> \#set
>> 
>> Similarly, only need to escape $<foo> when <foo> is something that has a
>> value in the context.
>> 
>> Otherwise, all other cases should render 'as is'.
>> 
>> Geir
>> 
> 
> 

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



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


Re: Quick Escaping Question

Posted by Tim Chamberlain <tc...@sportingnews.com>.
Hello again,

Im still having the same problem trying to print a #.  
I have tried to accomplish this with the following lines of code:

<td align=center class=v10><b>#</b></td>        
<td align=center class=v10><b> # </b></td>
<td align=center class=v10><b>\#</b></td>

The first two render nothing and the third gives me a \.

The same thing happens if I replace the # with a $.  I am trying to do 
this within a #if statement within a #macro using version 1.2, if that 
makes any difference.  
Any thougths?

Thanks again,
Tim

Geir Magnusson Jr. wrote:

>On 11/5/01 5:02 PM, "Tim Chamberlain" <tc...@sportingnews.com> wrote:
>
>>Hello List,
>>
>>I have a quick question about escaping characters.  In a template I am
>>trying to output #.   If I simply type #, nothing is printed out.
>>
>
>A # should be printed out.  What version of velocity are you using?
>
>> The 
>>manual talks about escaping $ with \$ but I did not see escaping the
>>pound sign anywhere.  I tried the same technique with # (ie \#), but \
>>was printed out instead of the #  I was expecting.  Is it possible to
>>escape the pound character?
>>
>>Thanks in advance,
>>Tim
>>
>
>You only need to escape #<token> when <token> is a valid directive, like
>
>\#set
>
>Similarly, only need to escape $<foo> when <foo> is something that has a
>value in the context.
>
>Otherwise, all other cases should render 'as is'.
>
>Geir
>


Re: Quick Escaping Question

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/5/01 5:02 PM, "Tim Chamberlain" <tc...@sportingnews.com> wrote:

> Hello List,
> 
> I have a quick question about escaping characters.  In a template I am
> trying to output #.   If I simply type #, nothing is printed out.

A # should be printed out.  What version of velocity are you using?

>  The 
> manual talks about escaping $ with \$ but I did not see escaping the
> pound sign anywhere.  I tried the same technique with # (ie \#), but \
> was printed out instead of the #  I was expecting.  Is it possible to
> escape the pound character?
> 
> Thanks in advance,
> Tim

You only need to escape #<token> when <token> is a valid directive, like

\#set

Similarly, only need to escape $<foo> when <foo> is something that has a
value in the context.

Otherwise, all other cases should render 'as is'.

Geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



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