You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ve...@jakarta.apache.org on 2005/02/07 23:38:50 UTC

[Jakarta-Velocity Wiki] New: VelocityWhitespaceGobbleStructuredTemplates

   Date: 2005-02-07T14:38:50
   Editor: ChristophReck
   Wiki: Jakarta-Velocity Wiki
   Page: VelocityWhitespaceGobbleStructuredTemplates
   URL: http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbleStructuredTemplates

   no comment

New Page:

Arguments in favour of the structured whitespace handling.

The typical use scenario for velocity is to add VTL markup to text pages. Two forms can be differentiated:
 * a velocity directive on a line by itself
 * directives embedded within other text.

In the first case, it is desireable to allow indenting the markup to better visualize the constructs; OTOH, the rendered output should not contain the whitespace indentation at the line begginning and the linefeed at the end. Example: {{{
#foreach( $i in [1..3] )
  $i
  #if( $i > 1 )
  --
  #end
#end
}}} 

For the second case, with embedded directives in a line, surrownding whitespaces should '''not''' be gobbled. A typical example of this from is: {{{
You selected:#if( $value ) $value#else nothing#end
}}}

This proposal does not deal/affect VTL-references.

Very rare cases exist where VTL-markup is embedded in non-line based files (binary?). For such uses, it is desireable to allow switching off the whitespace gobbling as a whole. A nice solution would be to add a pragma directive: {{{
#pragma( whitespace-gobbling off ) }}}

This should turn the gobbling off only within the declaring template. It should not affect any outer template parsing a template declaring the whitepace handling pragma.


The implementation of this proposal implies that the velocity parser must be aware of whitespaces before and after directives, and that during rendering tese are handled according to the whitepace handling pragma switch.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org