You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2000/11/08 00:17:34 UTC
Escape handling Mk II (new code committed)
Symmetry be damned, indeed.
The code for escape handling v2 is now in. Thanks to all for the
comments and discussion. I hope that this will be satisfactory to
everyone. If not, I am sure that y'all will speak up.
To review, the point of this is to make Velocity / VTL as non-invasive
to the schmoo, the non-VTL content in the template.
Simply put :
1) The '\' character acts as a conventional bind-from-the-left escape
character if and only if it appears on the left side of a VTL reference
or directive.
2) In all other cases, it is just a '\'
VTL reference := a syntax element $<name> such that a <name>,Object pair
is found in the Context.
VTL directive := a control directive or a pluggable directive, currently
including #set, #if, #else, #elsif, #end, #foreach, #include, #parse,
#macro and #stop.
Examples :
With $foo in the Context, it is 'active':
$foo renders as <foo>
\$foo renders as \$foo
\\$foo renders as \<foo> (because it binds from the left)
\\\$foo renders as \\$foo
With $foo NOT in the context, it's just text:
$foo renders as $foo
\$foo renders as \$foo
\\$foo renders as \\$foo
Directives :
#include("a.txt") renders as <contents of a.txt>
\#include("a.txt") renders as \#include("a.txt")
\\#include("a.txt") renders as \<contents of a.txt>
etc
\#if(true) hi \#end renders as #if(true) hi #end
\\#if(true) hi \\#end renders as \ hi \
\\\#if(true) hi \\#end is a parsing error after 'hi' :) (because the #if
is escaped, so there is a #end just sitting there )
Take a look at test/templates/escape2.vm for more good examples.
geir
--
Geir Magnusson Jr. geirm@optonline.com
Dakota tribal wisdom: "when you discover you are riding a dead horse,
the best strategy is to dismount."