The most reliable way to do this is to use

#set ($h = '#')

And then ${h} whenever you want a # to appear.  (or ${esc.h} without
the #set if you have the escape tool installed)

This works in all cases exactly as you'd expect.   Avoid using \ to
escape things -- it's not intuitively obvious how it works.

On 11/18/05, Will Glass-Husain <[EMAIL PROTECTED]> wrote:
> Velocity's silly escaping rules insist that you put the slash before a
> directive \#if
> but not before a # by itself.  Just leave off the slash.
>
> WILL
>
> ----- Original Message -----
> From: "Gérard BUNEL" <[EMAIL PROTECTED]>
> To: <velocity-user@jakarta.apache.org>
> Sent: Friday, November 18, 2005 1:07 AM
> Subject: How to put # in the string
>
>
> > Hello,
> >
> > I need to insert a # character in my template but doing so, like in
> > example2 modified below, I get an Error:
> >
> >        String s = "We are using $project $name to render this.\\#";
> >        w = new StringWriter();
> >
> >        try
> >        {
> >            Velocity.evaluate( context, w, "mystring", s );
> >        }
> >
> > ParseErrorException : org.apache.velocity.exception.ParseErrorException:
> > Lexical
> > error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at
> > line
> > 1, column 47.  Encountered: <EOF> after : ""
> >
> > So how could I insert this character in my template ?
> >
> > --
> > BUNEL Gerard - ATLANTIDE
> > Consultant
> > Tel. : +33 (0)2 98 05 43 21
> > http://www.ago.fr/
> > --
> > Technopôle Brest Iroise
> > Site du Vernis - CS 23866
> > 29238 Brest Cedex 3 - France
> > Tel. : +33 (0)2 98 05 43 21
> > Fax. : +33 (0)2 98 05 20 34
> > e-mail: [EMAIL PROTECTED]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to