You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Heimerl, Kurtis" <kh...@amazon.com> on 2005/11/15 19:59:34 UTC

Newline issues

I have a number of velocity macros that seem to be adding newlines, and i'm wondering if there is any easy way around this problem. The two offending macros are:
 
#macro (getMonths $month)
#if ($month == 0)
Jan #elseif($month == 1)
Feb 
#elseif($month == 2)
Mar 
#elseif($month == 3)
Apr 
#elseif($month == 4)
May 
#elseif($month == 5)
Jun
#elseif($month == 6)
Jul
#elseif($month == 7)
Aug
#elseif($month == 8)
Sept
#elseif($month == 9)
Oct
#elseif($month == 10)
Nov
#elseif($month == 11)
Dec
#else
##nothing
#end
#end
 
and
 
#macro (adjustYear2k $year)##plus 1900, date object returns years since 1900
#set ($year = $year + 1900)
$year
#end
 
when put into this block of vm code (ignore the depreciated date object)
#set ($year = ${popupModel.batchInfo.getBatchStartDate().getYear()})
#set ($month = ${popupModel.batchInfo.getBatchStartDate().getMonth()})
#set ($hour = ${popupModel.batchInfo.getBatchStartDate().getHours()})
#set ($minute = ${popupModel.batchInfo.getBatchStartDate().getMinutes()})
#set ($temp = "#getMonth($month)")
#set ($temp2 = "#adjustYear2k($year)")
#set ($temp = "${popupModel.batchInfo.getBatchStartDate().getDate()} ${temp} ${temp2}")
<td>Upload Start Date<br/><input type="text" readonly="readonly" value='${temp}'/></td>
 
i get the following html:
<td>Upload Start Date<br/><input type="text" readonly="readonly" value='27 Oct
  2005
'/>
 
This causes the 2005 to not be rendered, as it's outside the input object's one line. I need to remove the newlines that are causing the spacing after the macro calls, but i can't seem to find where/how to do this. The extra sets are my feeble attempts to diagnose the issue. I've tried removing all the newlines from the macros, making them single line functions. This didn't work. There has to be an easy way to do this, vtl is a templating language, it's all about data formatting! 
 
Any help would be appreciated. 
Kurtis

Re: Newline issues

Posted by Mike Kienenberger <mk...@gmail.com>.
If you end a line with "##", the rest of the line, including the
newline, is discarded from the output.

So you'd do....

#macro (getMonths $month)##
#if ($month == 0)##
Jan #elseif($month == 1)##
Feb##

and so on.

On 11/15/05, Heimerl, Kurtis <kh...@amazon.com> wrote:
> I have a number of velocity macros that seem to be adding newlines, and i'm wondering if there is any easy way around this problem. The two offending macros are:
>
> #macro (getMonths $month)
> #if ($month == 0)
> Jan #elseif($month == 1)
> Feb
> #elseif($month == 2)
> Mar
> #elseif($month == 3)
> Apr
> #elseif($month == 4)
> May
> #elseif($month == 5)
> Jun
> #elseif($month == 6)
> Jul
> #elseif($month == 7)
> Aug
> #elseif($month == 8)
> Sept
> #elseif($month == 9)
> Oct
> #elseif($month == 10)
> Nov
> #elseif($month == 11)
> Dec
> #else
> ##nothing
> #end
> #end
>
> and
>
> #macro (adjustYear2k $year)##plus 1900, date object returns years since 1900
> #set ($year = $year + 1900)
> $year
> #end
>
> when put into this block of vm code (ignore the depreciated date object)
> #set ($year = ${popupModel.batchInfo.getBatchStartDate().getYear()})
> #set ($month = ${popupModel.batchInfo.getBatchStartDate().getMonth()})
> #set ($hour = ${popupModel.batchInfo.getBatchStartDate().getHours()})
> #set ($minute = ${popupModel.batchInfo.getBatchStartDate().getMinutes()})
> #set ($temp = "#getMonth($month)")
> #set ($temp2 = "#adjustYear2k($year)")
> #set ($temp = "${popupModel.batchInfo.getBatchStartDate().getDate()} ${temp} ${temp2}")
> <td>Upload Start Date<br/><input type="text" readonly="readonly" value='${temp}'/></td>
>
> i get the following html:
> <td>Upload Start Date<br/><input type="text" readonly="readonly" value='27 Oct
>   2005
> '/>
>
> This causes the 2005 to not be rendered, as it's outside the input object's one line. I need to remove the newlines that are causing the spacing after the macro calls, but i can't seem to find where/how to do this. The extra sets are my feeble attempts to diagnose the issue. I've tried removing all the newlines from the macros, making them single line functions. This didn't work. There has to be an easy way to do this, vtl is a templating language, it's all about data formatting!
>
> Any help would be appreciated.
> Kurtis
>
>

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