Speed ​​directives also add spaces?

I just found out that with apache speed directives are also added to spaces.

So for example:

#foreach ($record in $rows) #foreach($value in $record) $value #end #end 

With something like this, I get extra lines for #foreach statements, #end , etc.

This is not what I want, so I found that I could block the comment at the end of the lines as follows:

 #foreach ($record in $rows)#* *##foreach($value in $record)#* *#$value #* *##end #end 

But it's pretty ugly to read. Is there a way to tell the speed engine not to format my directives?

Maybe I'm doing something else wrong?

Thanks.

+7
source share
2 answers

I think you are stuck with it (see Velocity Whitespace Gobbling ), although the comments on the line will be slightly neater:

 #foreach ($record in $rows)## #foreach($value in $record)## $value ## #end #end 

Or you can just compress everything on one line:

 #foreach($record in $rows)#foreach($value in $record)${value}#{end}#{end} 
+4
source

This is actually common for almost all template languages, and reasoning comes directly from simplified processing. Consider the following example (this is actually the GSP used by Grails, but the idea is the same):

 <g:each var="x" in="exes"> ${xy} </g:each> 

The processing method is that the tag is first identified (or in the Velocity directive, directive). Since the tag / directive itself contains instructions for processing the body of the tag, the tag of the tag / directive is deleted, and all content immediately after the start tag and immediately before the end tag is used as the target for processing. This includes all the gaps, because cleaning up the output will be much more difficult.

This, of course, does not mean that you cannot do this, as Edd points out, or that this will be the most reasonable design choice in the first place, but sometimes doing something is simpler than creating beautiful layouts - After all, most, if not all markup processors don't care if you have <p>some\ncontent</p> or <p>some\n\n\n\t\tcontent</p> .

+1
source

All Articles