You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by pl...@netscape.net on 2002/08/02 20:07:07 UTC

Tips for Readable Templates

Does anyone have any tips for keeping Velocity templates readable?
I keep running into cases where I have write a macro that doesn't 
introduce any extra whitespace, which means (I think) that all
of my #diretives need to be at the left margin of the file, without
any indentation to show nesting of statements.  This makes the macros
very difficult to read, especially when the #directives are intermixed
with HTML which must also be at the left margin.

Is there any work-around for this problem?

I did discover that the statement:
#   #set($a='hi')
will set $a to hi and not print the first #, but I think that is a
bug.  (#if and #end don't work that way.)

Thanks in advance for suggestions,
   --Paul


__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Tips for Readable Templates

Posted by Ch...@dlr.de.
This is again the whitespace gobbling issue that has not reached any
consensus yet. I believe that my proposed solutionis in the "Whitespace, redux"
thread is what most people would expect:

If a line is looks like this:
   DirectiveLine ::= LineEnd TabsAndSpaces? Markup TabsAndSpaces? LineEnd
   TabsAndSpaces ::= (#x20 | #x09)+
   LineEnd       ::= StartOfStream | ((#x0D #x0A) | #x0D | #x0A) | EndOfStream
   Markup        ::= Directive | ## | Multi-line-comment
   Multi-line-comment ::= (#**? ((#x0D #x0A) | #x0D | #x0A) *?*#)
then the first "TabsAndSpaces?" and the closing "TabsAndSpaces? LineEnd"
should be gobbled. (Note that it supports multiline directives, that is
why "DirectiveLine" is not simply "Line".) If you whant the first
"LineEnd" to be gobbled prepend a ## before it (it is part of the
previous line!).


For the moment for pretty indented output I do:

#macro( macroName $foo $indent )#*
   *##set( $bar = $foo.woogie() )#*
   *#foreach( ... )#*
     *##if( ... )#*
       *#${indent}...
     #end#*
   *##end#*
*##end

or:

#macro( macroName $foo $indent )
#**##set( $bar = $foo.woogie() )##
#**#foreach( ... )##
#*  *##if( ... )##
#*    *#${indent}...
#*  *##end##
#**##end##
#end

plynchnlm@netscape.net wrote:
> Does anyone have any tips for keeping Velocity templates readable?
> I keep running into cases where I have write a macro that doesn't 
> introduce any extra whitespace, which means (I think) that all
> of my #diretives need to be at the left margin of the file, without
> any indentation to show nesting of statements.  This makes the macros
> very difficult to read, especially when the #directives are intermixed
> with HTML which must also be at the left margin.
> 
> Is there any work-around for this problem?
> 
> I did discover that the statement:
> #   #set($a='hi')
> will set $a to hi and not print the first #, but I think that is a
> bug.  (#if and #end don't work that way.)
> 
> Thanks in advance for suggestions,
>    --Paul
> 
> 
> __________________________________________________________________
> Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
> 
> Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


-- 
:) Christoph Reck


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>