You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Johnny Cass <jo...@epiuse.com> on 2002/06/05 11:34:02 UTC

Template demarcation comments

Hi,

We combine a lot of different Velocity templates dynamically (using 
#parse directives) to generate HTML pages. It is sometimes difficult to 
'debug' these pages since it might not be immediately obvious *which* 
template was responsible for rendering which particular fragment of HTML.

We have started adding <!-- templateName.vm begin --> and <!-- 
templateName.vm end --> HTML comments to the very top and bottom of our 
templates so that the comments will show up in the rendered HTML and 
make it easier to track bugs.

My question is: Is it possible to specify headers and footers like these 
to be added to all rendered templates automatically? Is this a feature 
that might be worth adding?

Have any of you had similar problems and, if so, how did you solve them?

Thank you for your time.
-Johnny.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Template demarcation comments

Posted by Simon Christian <si...@cpd.co.uk>.

Johnny Cass wrote:
> Simon Christian wrote:
> 
>> Hi Johnny,
>>
>> I've not tried this, but could you not use a macro e.g.:
>>
>> #macro( #myparse $filename )
>> <!-- $filename begin -->
>> #parse( $filename )
>> <!-- $filename end -->
>> #end
> 
> 
> This looks like a really good idea. My only concern is that the 
> additional macro call on *every* parse might have a significant 
> performance penalty? Will this be the case?
> 

I've just done a few simple tests to compare, and as expected ys there 
is a hit, but not a huge one. From the listings below, I tested with the 
macro defined header/footer using 'macro.vtl' and doing it inline each 
time 'inline.vtl', in each case just parsing in the 'test.vtl' file.

There was actually other gunk on the page from a seperate application, 
but that was rendered in a consistent 3ms each time.

Had to run many times to get any differentiation, but the following 
results were obtained (All times in ms, average taken of 3 renders):

no. loops   inline   macro
1000        22       26
5000        92       120
10000       180      260
20000       360      530

So yes there is a difference, but unless you're using a LOT of #parse 
statements or I guess are running on a slow machine, you're not really 
going to notice it. Also, in this test all the overhead is in the macro 
and parse processes with very little content - in a real-world 
environment you're likely to do much more work within the parsed files.

- simon


File listings:
########## test.vtl #########
<!-- test -->


########## macro.vtl ########
#macro( myparse $filename )
<!-- begin $filename -->
#parse( $filename )
<!-- end $filename -->
#end

#set( $myfile = "test.vtl" )
#foreach( $i in [1..5000] )
#myparse( $myfile )
#end


########## inline.vtl #########
#set( $filename = "test.vtl" )
#foreach( $i in [1..5000] )
<!-- begin $filename -->
#parse( $filename )
<!-- end $filename -->
#end



> Thanks.
> -Johnny
> 
>>
>> - simon
>>
>> Johnny Cass wrote:
>>
>>> Hi,
>>>
>>> We combine a lot of different Velocity templates dynamically (using 
>>> #parse directives) to generate HTML pages. It is sometimes difficult 
>>> to 'debug' these pages since it might not be immediately obvious 
>>> *which* template was responsible for rendering which particular 
>>> fragment of HTML.
>>>
>>> We have started adding <!-- templateName.vm begin --> and <!-- 
>>> templateName.vm end --> HTML comments to the very top and bottom of 
>>> our templates so that the comments will show up in the rendered HTML 
>>> and make it easier to track bugs.
>>>
>>> My question is: Is it possible to specify headers and footers like 
>>> these to be added to all rendered templates automatically? Is this a 
>>> feature that might be worth adding?
>>>
>>> Have any of you had similar problems and, if so, how did you solve them?
>>>
>>> Thank you for your time.
>>> -Johnny.
>>>
>>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Template demarcation comments

Posted by Johnny Cass <jo...@epiuse.com>.
Simon Christian wrote:
> Hi Johnny,
> 
> I've not tried this, but could you not use a macro e.g.:
> 
> #macro( #myparse $filename )
> <!-- $filename begin -->
> #parse( $filename )
> <!-- $filename end -->
> #end

This looks like a really good idea. My only concern is that the 
additional macro call on *every* parse might have a significant 
performance penalty? Will this be the case?

Thanks.
-Johnny

> 
> - simon
> 
> Johnny Cass wrote:
> 
>> Hi,
>>
>> We combine a lot of different Velocity templates dynamically (using 
>> #parse directives) to generate HTML pages. It is sometimes difficult 
>> to 'debug' these pages since it might not be immediately obvious 
>> *which* template was responsible for rendering which particular 
>> fragment of HTML.
>>
>> We have started adding <!-- templateName.vm begin --> and <!-- 
>> templateName.vm end --> HTML comments to the very top and bottom of 
>> our templates so that the comments will show up in the rendered HTML 
>> and make it easier to track bugs.
>>
>> My question is: Is it possible to specify headers and footers like 
>> these to be added to all rendered templates automatically? Is this a 
>> feature that might be worth adding?
>>
>> Have any of you had similar problems and, if so, how did you solve them?
>>
>> Thank you for your time.
>> -Johnny.
>>
> 
> 
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Template demarcation comments

Posted by Simon Christian <si...@cpd.co.uk>.
Hi Johnny,

I've not tried this, but could you not use a macro e.g.:

#macro( #myparse $filename )
<!-- $filename begin -->
#parse( $filename )
<!-- $filename end -->
#end

- simon

Johnny Cass wrote:
> Hi,
> 
> We combine a lot of different Velocity templates dynamically (using 
> #parse directives) to generate HTML pages. It is sometimes difficult to 
> 'debug' these pages since it might not be immediately obvious *which* 
> template was responsible for rendering which particular fragment of HTML.
> 
> We have started adding <!-- templateName.vm begin --> and <!-- 
> templateName.vm end --> HTML comments to the very top and bottom of our 
> templates so that the comments will show up in the rendered HTML and 
> make it easier to track bugs.
> 
> My question is: Is it possible to specify headers and footers like these 
> to be added to all rendered templates automatically? Is this a feature 
> that might be worth adding?
> 
> Have any of you had similar problems and, if so, how did you solve them?
> 
> Thank you for your time.
> -Johnny.
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>