velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: How to keep '$' Char in .vm files?
Date Tue, 28 Aug 2007 22:10:20 GMT
On 8/28/07, angelcervera <angel@acervera.com> wrote:
>
>
> Marco Schoolenberg wrote:
> >
> > I seem to remember that escaping the character is the Normal thing to
> > do...
> >
>
> In "User Guide" said:
>
> Velocity User Guide wrote:
> >
> > VTL directives can be escaped with the backslash character ("\") in a
> > manner similar to valid VTL references.
> >
>
> But using this template:
>
>
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> > Commons Validator Rules Configuration 1.1.3//EN"
> > "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> > <form-validation>
> > <arg2 key="\${var:maxlength}" name="maxlength" resource="false" />
> > </form-validation>
> >
>
> Return this error:
>
>
> > org.apache.velocity.exception.ParseErrorException: Encountered
> > ":maxlength}\" name=\"maxlength\" resource=\"false\"
> > />\n</form-validation>\n" at line 4, column 18.
> > Was expecting one of:
> >     "}" ...
> >     <DOT> ...
> >
> >         at org.apache.velocity.Template.process(Template.java:141)
> >
>
> Using this template all go ok (special attention in removed character $):
>
>
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
> > Commons Validator Rules Configuration 1.1.3//EN"
> > "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
> > <form-validation>
> > <arg2 key="{var:maxlength}" name="maxlength" resource="false" />
> > </form-validation>
> >
>
> So, in conclusion, "$" it's not escaped with "\" character.

correct.  the escaping is for "VTL references" as opposed to escaping
the $ char, and unfortunately ${var:maxlength} is not a valid VTL
reference.

to properly escape the $ char, you simply need to do

#set( $D = '$' )

and then do ${D}{var:maxlength}

> I'm using velocity 1.4

this is true for all versions.

> Thank's
> --
> View this message in context: http://www.nabble.com/How-to-keep-%27%24%27-Char-in-.vm-files--tf4038353.html#a12376953
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Mime
View raw message