You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "White, Tim" <Ti...@qwest.com> on 2004/10/22 20:30:27 UTC
Debugging Template
Hi -
I've worked a lot with the PHP templating system, Smarty, and I've
adapted it's handy debugging console for Velocity.
Essentially, if you put the code below into a template called
"debug.vm", and you #parse it at the end of the template you want to
debug (after the </html> tag), it will pop up a window with all of the
context variables in it, so you can see what is being passed to your
template. (Thanks to Dan Chapman for working on this as well).
Enjoy!
Tim White
----------
#macro (printRow $name $value)
#set ($rowLength = $value.length()/57+1)
#if ($rowLength > 15)
#set ($rowLength = 15)
#end
#if (($velocityCount % 2) == 0)
_velocity_console.document.write("<tr
bgcolor=#fafafa>");
#else
_velocity_console.document.write("<tr
bgcolor=#eeeeee>");
#end
_velocity_console.document.write("<td valign=top><tt><font
color=maroon>$" + "$name" + "</font></tt></td>");
#if ($rowLength == 1)
_velocity_console.document.write("<td><tt><font
color=green>$value</font></tt></td></tr>");
#else
_velocity_console.document.write("<td><tt><font
color=green><textarea rows=$rowLength cols=57>");
_velocity_console.document.write("$value");
_velocity_console.document.write("</textarea></font></tt></td></tr>");
#end
#end
<script language=javascript>
_velocity_console =
window.open("",true,"width=680,height=600,resizable,scrollbars=yes");
_velocity_console.document.write("<html><head><title>Velocity
Debug Console</title></head><body bgcolor=#ffffff>");
_velocity_console.document.write("<table border=0 width=100%>");
_velocity_console.document.write("<tr bgcolor=#000000><th
colspan='2'><b><font color=#FFFFFF>Velocity Debug
Console</font></b></td></tr>");
_velocity_console.document.write("<tr bgcolor=#cccccc><td
colspan='2'><b>Request Attributes:</b></td></tr>");
#foreach ($name in $request.getAttributeNames())
#printRow($name
$request.getAttribute($name).toString().replaceAll("\n", "\\n"))
#end
_velocity_console.document.write("<tr bgcolor=#cccccc><td
colspan='2'><b>Request Parameters:</b></td></tr>");
#foreach ($name in ${request.getParameterNames()})
#printRow($name
$request.getParameter($name).toString().replaceAll("\n", "\\n"))
#end
_velocity_console.document.write("<tr bgcolor=#cccccc><td
colspan='2'><b>Session Attributes:</b></td></tr>");
#foreach ($name in ${session.getAttributeNames()})
#printRow($name
$session.getAttribute($name).toString().replaceAll("\n", "\\n"))
#end
_velocity_console.document.write("</table>");
_velocity_console.document.write("</body></html>");
_velocity_console.document.close();
</script>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Debugging Template
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Tim,
> I've worked a lot with the PHP templating system, Smarty, and I've
> adapted it's handy debugging console for Velocity.
>
> Essentially, if you put the code below into a template called
> "debug.vm", and you #parse it at the end of the template you want to
> debug (after the </html> tag), it will pop up a window with all of the
> context variables in it, so you can see what is being passed to your
> template. (Thanks to Dan Chapman for working on this as well).
Cool! Could you get this up on the Wiki site? Maybe under VelocityViewMacros?
http://wiki.apache.org/jakarta-velocity/VelocityViewMacros
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org