velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Escaping Quotes and/or string concatenation
Date Fri, 11 May 2001 00:20:59 GMT
> 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..."

Mime
View raw message