velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Christian <si...@cpd.co.uk>
Subject Re: indentation of templates
Date Tue, 12 Mar 2002 09:23:15 GMT
Should the #if directive be gobbling the whitespace before it? I've 
found the same effect as you evidently have, but get around it by 
starting the #if and #else directives at the beginning of the line i.e.

#if (this-is-true)
	output true stuff
	$context.applyTemplates("section")
#else
	output false stuff
	#execute_a_macro()
#end

I agree wholeheartedly with you on the desired output formatting, just 
not sure that anything has gone *wrong* in Velocity in this case.

- s


Bill Burton wrote:

> Hi Sebastien,
> 
> Glad to hear you like Velocity.
> 
> I have recently run into the same extra whitespace issue while working on
> a DVSL stylesheet.  The #if directive never seems to gobble up leading
> whitespace even if it's the only thing on the line.  Whereas the #set
> directive does do this.
> 
> What I did to allow indentation of directives while eliminating the extra
> whitespace is to use multiline comments to hide whitespace.  If these
> comments are used before #if, #else, #elseif and matching #end's as well
> as before invoking other tools or macros, you can get the output to be
> indented properly.  Here's an example:
> 
> #*       *##if (this-is-true)
>            output true stuff
> #*         *#$context.applyTemplates("section")
> #*       *##else
>            output false stuff
> #*         *##execute_a_macro()
> #*       *##end
> 
> Even though the above looks odd, I like it much better than putting
> everything flush left.
> 
> The only thing is once in a while, I've forgotten the # before the
> directive and put *#else instead of *##else.
> 
> If you need to eliminate blank lines, start the #* at the end of the prior
> line to comment out the enclosed newline.
> 
> -Bill
> 



--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message