"Geir Magnusson Jr." wrote:
> 
> jeff wrote:
> >
> > As I understand it, escaping the $ char is context sensitive.  i.e.
> > \$foo will render as $foo if $foo is defined but as \$foo if foo is
> > undefined.  To me this seems very unfortunate.  Suppose I want to create
> > a template fragment for use in many different templates which needs to
> > render a literal $foo.  This is impossible since I can never be sure
> > whether or not foo will be defined and so I won't know whether to put
> > \$foo or $foo in the fragment.
> >
> > Now this is not a huge problem, but it seems like an unnecessary one.
> > Why were escapes designed to work this way?
> 
> As I recall, the main point was that we don't want to have people modify
> their input content unnecessarily just because we decided that '$' is
> the start of our reference.  It's a trade off, but since vel is general
> purpose, we don't assume that each template is hand crafted by a
> designer - you could take random stuff, such as a news feed, add some
> VTL somewhere (such as search for stock tickers and put a link to your
> quote page...)  and run through the template engine, and it should do no
> harm to the material you didn't touch.

Is that really something you envision as a commonplace need?  Seems to
me like the vast majority of templates are going to be hand crafted by a
designer.  Not only that, but even if arbitrary text is used as source
material, how often does \$ occur except in some sort of template
language source?

> Could you use #if() ? #if($foo) -> false if $foo not in the context.

I hadn't thought of that.  It's a bit ugly but it would work.

> 
> Or
> 
> #set($blarg123 = '$foo' )
>  $blarg123
> 
> should work too...  Of course, you then have to worry about 'blarg123'
> in your context...
> 
> I understand your problem, but I hope you can see some of the
> reasoning.  Any suggestions?

I was going to suggest something to turn off parsing temporarily but I
searched my email archive and noticed that jvanzyl already added
#literal

I am concerned though, because he gave this as an example:

> #literal()
> 
> #if($skin)
>     $!data.setLayoutTemplate($!skin.getLayout())
>     $!page.setCss($!skin.getCss())
> #end
>  
> #end

This implies that parsing is still going on inside of the directive even
if no substitution is being done.  If the above works, then the
following could not possibly work:

#literal()

#if($skin)
    $!data.setLayoutTemplate($!skin.getLayout())
    $!page.setCss($!skin.getCss())
#noend
 
#end


Perhaps #literal could be enhanced to allow this sort of usage:

#literal(ARBITRARY_END_MARKER_TEXT)

#if($skin)
    $!data.setLayoutTemplate($!skin.getLayout())
    $!page.setCss($!skin.getCss())
#noend
 
ARBITRARY_END_MARKER_TEXT

Reply via email to