velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <>
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" <> 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
> (
> 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
> 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>

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

I'm going to fix this :)


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

Do You Yahoo!?
Get your free address at

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message