You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Darren Gilroy <DG...@CONSONUS.com> on 2001/05/10 18:56:43 UTC
Escaping Quotes and/or string concatenation
Hi -
I have a macro defined:
#macro (cell $body)
<td>$body</td>
#end
I am having difficulty using the macro when I have embedded quotes in the
string. For example
#cell ( "<a href="$link.setPage("Index.vm")">Home</a>" )
throws a "to many arugments" error (understandable)
#cell ( "<a href=\"$link.setPage("Index.vm")\">Home</a>" )
throws: Turbine.handleException: Lexical error at line 17, column 50.
Encountered: "v" (118), after : "." (understandable, sort of)
#cell ( "<a href=\"$link.setPage('Index.vm')\">Home</a>" )
outputs: <a
href="\"http://server/reportadmin/servlet/reportadmin/template/Index.vm\">ad
min</a> (hmmm..)
Similar combinations have similar results. Any suggestions on how this
string should work? Right now my work-around is to use:
#cell ( "<a href=$link.setPage('Index.vm')>Home</a>" )
but href strings *should* be quoted.
Ideas?
-best-darr-
Re: Escaping Quotes and/or string concatenation
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
> Darren Gilroy wrote:
>
> Hi -
>
> I have a macro defined:
>
> #macro (cell $body)
>
> <td>$body</td>
>
> #end
>
> I am having difficulty using the macro when I have embedded quotes in
> the string. For example
>
> #cell ( "<a href="$link.setPage("Index.vm")">Home</a>" )
>
> throws a "to many arugments" error (understandable)
>
> #cell ( "<a href=\"$link.setPage("Index.vm")\">Home</a>" )
>
> throws: Turbine.handleException: Lexical error at line 17, column 50.
> Encountered: "v" (118), after : "." (understandable, sort of)
>
> #cell ( "<a href=\"$link.setPage('Index.vm')\">Home</a>" )
>
> outputs: <a
> href="\"http://server/reportadmin/servlet/reportadmin/template/Index.vm\">admin</a>
> (hmmm..)
>
> Similar combinations have similar results. Any suggestions on how this
> string should work? Right now my work-around is to use:
>
> #cell ( "<a href=$link.setPage('Index.vm')>Home</a>" )
>
> but href strings *should* be quoted.
>
> Ideas?
sure. I am always full of it...
First, velocity doesn't support 'escaped' anything in strings. I did
some of the ground work for it, but no one seemed to care. If we care,
I can add.
Second, you can always use ' in " " or " in ' ' w/o fear. So
#macro( foo $string )
$string
#end
#set($bar = "http://www.yahoo.com/")
#foo( "<a href='$bar'>Home</a>")
produces the output
<a href='http://www.yahoo.com/'>Home</a>
is that what you want?
geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
Developing for the web? See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."
Re: Escaping Quotes and/or string concatenation
Posted by Jason van Zyl <jv...@apache.org>.
> Darren Gilroy wrote:
I can barely read your mail. Please don't send html mail.
>
> Hi -
>
> I have a macro defined:
>
> #macro (cell $body)
>
> <td>$body</td>
>
> #end
>
> I am having difficulty using the macro when I have embedded quotes in
> the string. For example
>
> #cell ( "<a href="$link.setPage("Index.vm")">Home</a>" )
>
> throws a "to many arugments" error (understandable)
>
> #cell ( "<a href=\"$link.setPage("Index.vm")\">Home</a>" )
>
> throws: Turbine.handleException: Lexical error at line 17, column 50.
> Encountered: "v" (118), after : "." (understandable, sort of)
>
> #cell ( "<a href=\"$link.setPage('Index.vm')\">Home</a>" )
>
> outputs: <a
> href="\"http://server/reportadmin/servlet/reportadmin/template/Index.vm\">admin</a>
> (hmmm..)
>
> Similar combinations have similar results. Any suggestions on how this
> string should work? Right now my work-around is to use:
>
> #cell ( "<a href=$link.setPage('Index.vm')>Home</a>" )
>
> but href strings *should* be quoted.
>
> Ideas?
>
> -best-darr-
--
jvz.
Jason van Zyl
jvanzyl@apache.org
http://jakarta.apache.org/velocity
http://jakarta.apache.org/turbine
http://jakarta.apache.org/commons
http://tambora.zenplex.org
Re: Escaping Quotes and/or string concatenation
Posted by Jon Stevens <jo...@latchkey.com>.
on 5/10/01 9:56 AM, "Darren Gilroy" <DG...@CONSONUS.com> wrote:
> Hi -
>
> I have a macro defined:
>
> #macro (cell $body)
> <td>$body</td>
> #end
>
> I am having difficulty using the macro when I have embedded quotes in the
> string. For example
>
> #cell ( "<a href="$link.setPage("Index.vm")">Home</a>" )
> throws a "to many arugments" error (understandable)
>
> #cell ( "<a href=\"$link.setPage("Index.vm")\">Home</a>" )
> throws: Turbine.handleException: Lexical error at line 17, column 50.
> Encountered: "v" (118), after : "." (understandable, sort of)
You missed two ""...
#cell ( "<a href=\"$link.setPage(\"Index.vm\")\">Home</a>" )
> #cell ( "<a href=\"$link.setPage('Index.vm')\">Home</a>" )
> outputs: <a
> href="\"http://server/reportadmin/servlet/reportadmin/template/Index.vm\">ad
> min</a> (hmmm..)
That looks like a bug to me.
Needless to say, I don't think that level of abstraction is a good thing. It
makes your templates look very ugly. It is far better to use a carefully
done CSS style sheet for that type of formatting or you should look into
using Velocity in Anakia mode which simulates a XSLT processor.
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>