on the line of this thread...
Sometimes I use the #*...*# spanning a line to allow for structured templates; also some macros help making the implicit formatting visible:
## #macro( print $text )$text#end ## #macro( println $text )$text #end ## #macro( testMacro )#* *##if ( <some condition> )#* *##println( "This output will not have any leading whitespace, nor trailing" )#* *##print( "whitespace because everything is embedded between block comments" )#* *##else Without the block comments, these lines have extra spaces and a new line which wrecks your template output. #end #end
But as you can see it is hard work to get structured templates with pretty output. The templates remain only partially pretty/readable :I
Cheers, Christoph
Will Glass-Husain wrote:
That's very clever. Thanks for sharing it.
This type of approach would probably help a lot of users - We should probably add it to the docs.
WILL
----- Original Message ----- From: "Barrie Treloar" <[EMAIL PROTECTED]> To: <velocity-user@jakarta.apache.org> Sent: Sunday, February 06, 2005 3:44 PM Subject: Semi-workaround for the Whitespace gobbling problem
To avoid having to collapse your macros into an unreadable mess you can use the below hack to work around this.
Use the Velocity line comment syntax "##" to terminate the text that will be inserted, this will mean that newlines are no longer added.
The whitespace after the #if directive seems to be ignored so you can write constructs like this:
#macro( testMacro ) #if ( <some condition> ) This output will not have any leading whitespace, nor trailing whitespace because the line is terminated via the line comment## #else Without the line comment, this line has an extra new line which wrecks your template. #end #end
Enjoy Bae
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]