velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <geirmagnusso...@yahoo.com>
Subject Re: escaped quotes in #set directive for string literals
Date Mon, 12 Nov 2001 19:25:54 GMT
On 11/12/01 1:51 PM, "LS" <alphafoo@yahoo.com> wrote:

> Hi, I'm trying to figure out the best way to get quoted strings to work with
> #set.
> I've checked the archives and found a thread on this back in July
> (http://www.mail-archive.com/velocity-user@jakarta.apache.org/msg02560.html)
> that
> indicated that this issue was a point of contention.
> 
> To recap, I am trying to do something like this
> 
> #set ($href = "<a href="foo.m?bar=$schmoo">Hi</a>")
> $href
> 
> so that I would see the inner quotes in the final HTML output.
> 
> If I escape them with \, then the \'s end up in the final output, which is
> bad.
> 

Right - not supported - that's another project for me this trip...

> If I use single quotes on the outside and double quotes internally, then the
> single
> quotes keep the contents from being parsed, unless I tweak the
> velocity.properties
> file to disable this, which I'd rather not do.
> 
> If you have handled this in the past, how did you do it?

Some people do 

#set($dq = '"')
#set($href = "<a href=${dq}foo.m?bar?$schmoo${dq}>Hi</a>")

Which is ugly and painful.

A good one that was suggested was a Velocimacro :

#macro (href $link $text )
  <a href="$link">$text</a>
#end

And then use as

#set($link = "foo.m?$schmoo" )
#set($href = "#href( $link 'Hi' )")

Or just

#href( "foo.m?$schmoo" 'Hi' )

While not a lot of fun, it gives you the ability to localize how hrefs are
created...

I'm going to fix this :)

geir


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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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


Mime
View raw message