velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <>
Subject Re: Quoting a document
Date Sun, 12 Dec 2004 05:37:08 GMT
Hi Charles,

> I'm about to deploy Velocity for generating UNIX config files. To help
> build the templates, I'd like to be able to run the original config files
> (off which the templates will be based) though a quoting process which
> generates a VTL template which will precisely recreate the original
> document.
> However, my naive efforts to build such a tool have so far failed.

## snip

> However, both of these have generated templates with backslashes which
> persisted in Velocity's final output files but did not exist in the
> originals.
> Is there a straightforward way to do what I'm attempting? If not, might
> anyone suggest a tool more appropriate than VTL to the end I'm trying to
> accomplish?

I can't explain Velocity's escaping scheme (mainly because the
documentation is wrong and I don't understand it), but the general
concept is that if something wasn't meant for Velocity, it must be
what the template designer wants (called schmoo, BTW).  eg. if the
reference "foo" existed, "\$foo" will be rendered as "$foo", but it it
didn't, it will be rendered as "\$foo".

So what do you do?  Make Velocity render "$", "#", "\" no matter what.
 This is done by making a reference that renders those values.

There are 2 easy ways to do this.

1. Using EscapeTool (
Assuming that EscapeTool is put in the Context as $esc, make the
following changes:
  $ -> ${esc.d}
  # -> ${esc.h}
  \ -> ${esc.b}

## Something like this:  sed 's/\$/\${esc.d}/g ; s/#/\${esc.h}/g ;

2. Do the same thing, only define the values in the template.  (You
don't need to set Tools this way.)
  #set($D = '$')
  #set($H = '#')
  #set($B = '\')
at the beginning of the file, and make the following changes:
  $ -> ${D}
  # -> ${H}
  \ -> ${B}

Best regards,
-- Shinobu Kawai

Shinobu Kawai <>

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

View raw message