View previous topic :: View next topic |
Author |
Message |
6 ANUR Smarty Rookie
Joined: 06 May 2003 Posts: 23 Location: Lille, France
|
Posted: Wed Sep 08, 2004 12:07 pm Post subject: Debug console |
|
|
Hi all,
I have recently taken a look into the debug.tpl template and I have found several bugs.
For example this code will not work if one change the delimiters from the default ones to custom values.
Code: |
if( self.name == '' ) {ldelim}
var title = 'Console';
{rdelim}
else {ldelim}
var title = 'Console_' + self.name;
{rdelim}
|
The generated HTML code is also invalid (Ie: No DocType, the title tag is not in the head section ...)
I volunteer to fix these issues if you want. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Sep 08, 2004 1:27 pm Post subject: |
|
|
That would be great, just post your patch when you're done. Thanks! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Sep 08, 2004 1:34 pm Post subject: |
|
|
no need to fix the delimiters. display_debug_console() takes care to set them to the working defaults.
but fixing the html would be great!
Last edited by messju on Wed Sep 08, 2004 1:45 pm; edited 1 time in total |
|
Back to top |
|
6 ANUR Smarty Rookie
Joined: 06 May 2003 Posts: 23 Location: Lille, France
|
Posted: Wed Sep 08, 2004 1:38 pm Post subject: |
|
|
messju wrote: | no need to fix the delimiters. display_debug_console() to takes to set them to the working defaults. |
Ok, I was not aware of that. |
|
Back to top |
|
6 ANUR Smarty Rookie
Joined: 06 May 2003 Posts: 23 Location: Lille, France
|
Posted: Wed Sep 08, 2004 4:14 pm Post subject: |
|
|
Ok, so here is the fixed version :
Code: |
{* Smarty *}
{* debug.tpl, last updated version 2.0.1 *}
{assign_debug_info}
{if isset($_smarty_debug_output) and $_smarty_debug_output eq "html"}
<table border="0" width="100%">
<tr bgcolor="#cccccc"><th colspan="2">Smarty Debug Console</th></tr>
<tr bgcolor="#cccccc"><td colspan="2"><b>included templates & config files (load time in seconds):</b></td></tr>
{section name=templates loop=$_debug_tpls}
<tr bgcolor="{if %templates.index% is even}#eeeeee{else}#fafafa{/if}"><td colspan="2"><tt>{section name=indent loop=$_debug_tpls[templates].depth}&&&{/section}<font color="{if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}">{$_debug_tpls[templates].filename|escape:html}</font>{if isset($_debug_tpls[templates].exec_time)} <font size="-1"><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>
{sectionelse}
<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no templates included</i></tt></td></tr>
{/section}
<tr bgcolor="#cccccc"><td colspan="2"><b>assigned template variables:</b></td></tr>
{section name=vars loop=$_debug_keys}
<tr bgcolor="{if %vars.index% is even}#eeeeee{else}#fafafa{/if}"><td valign="top"><tt><font color="blue">{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color="green">{$_debug_vals[vars]|@debug_print_var}</font></tt></td></tr>
{sectionelse}
<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no template variables assigned</i></tt></td></tr>
{/section}
<tr bgcolor="#cccccc"><td colspan="2"><b>assigned config file variables (outer template scope):</b></td></tr>
{section name=config_vars loop=$_debug_config_keys}
<tr bgcolor="{if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}"><td valign="top"><tt><font color="maroon">{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color="green">{$_debug_config_vals[config_vars]|@debug_print_var}</font></tt></td></tr>
{sectionelse}
<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no config vars assigned</i></tt></td></tr>
{/section}
</table>
{else}
<script type="text/javascript">
<!--
if( self.name == '' ) {ldelim}
var title = 'Console';
{rdelim}
else {ldelim}
var title = 'Console_' + self.name;
{rdelim}
var _smarty_console = window.open('',title.value,'width=680,height=600,resizable,scrollbars=yes');
_smarty_console.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
_smarty_console.document.write('<html><head><title>Smarty Debug Console_'+self.name+'</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body bgcolor="#ffffff">');
_smarty_console.document.write('<table border="0" width="100%">');
_smarty_console.document.write('<tr bgcolor="#cccccc"><th colspan="2">Smarty Debug Console</th></tr>');
_smarty_console.document.write('<tr bgcolor="#cccccc"><td colspan="2"><b>included templates & config files (load time in seconds):</b></td></tr>');
{section name=templates loop=$_debug_tpls}
_smarty_console.document.write('<tr bgcolor="{if %templates.index% is even}#eeeeee{else}#fafafa{/if}"><td colspan="2"><tt>{section name=indent loop=$_debug_tpls[templates].depth}&&&{/section}<font color="{if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}">{$_debug_tpls[templates].filename|escape:html|escape:javascript}</font>{if isset($_debug_tpls[templates].exec_time)} <font size="-1"><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>');
{sectionelse}
_smarty_console.document.write('<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no templates included</i></tt></td></tr>');
{/section}
_smarty_console.document.write('<tr bgcolor="#cccccc"><td colspan="2"><b>assigned template variables:</b></td></tr>');
{section name=vars loop=$_debug_keys}
_smarty_console.document.write('<tr bgcolor="{if %vars.index% is even}#eeeeee{else}#fafafa{/if}"><td valign="top"><tt><font color="blue">{ldelim}${$_debug_keys[vars]}{rdelim}</font></tt></td><td nowrap><tt><font color="green">{$_debug_vals[vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>');
{sectionelse}
_smarty_console.document.write('<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no template variables assigned</i></tt></td></tr>');
{/section}
_smarty_console.document.write('<tr bgcolor="#cccccc"><td colspan="2"><b>assigned config file variables (outer template scope):</b></td></tr>');
{section name=config_vars loop=$_debug_config_keys}
_smarty_console.document.write('<tr bgcolor="{if %config_vars.index% is even}#eeeeee{else}#fafafa{/if}"><td valign="top"><tt><font color="maroon">{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></tt></td><td><tt><font color="green">{$_debug_config_vals[config_vars]|@debug_print_var|escape:javascript}</font></tt></td></tr>');
{sectionelse}
_smarty_console.document.write('<tr bgcolor="#eeeeee"><td colspan="2"><tt><i>no config vars assigned</i></tt></td></tr>');
{/section}
_smarty_console.document.write('</table></body></html>');
_smarty_console.document.close();
//-->
</script>
{/if}
|
I have made no changes to the logic nor the code. Only validation errors were fixed.
I have some improvement proposals :
- The following code does not seem to work and in fact I could not figure out its purpose.
Code: |
if( self.name == '' ) {ldelim}
var title = 'Console';
{rdelim}
else {ldelim}
var title = 'Console_' + self.name;
{rdelim}
|
- Now that the debug console validates, maybe it should also be more semantic (Ie: table free, use of CSS ...)
- For the javascript version, I think it would be great to add fold/unfold gadget for big assigned variables
I am also volonteer to make these improvements if you will. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Sep 08, 2004 5:11 pm Post subject: |
|
|
Actually, someone already went through the work of javascript fold/unfold debug console long ago, but it was never implemented. You can check the mailing list archive for it, that might be of some help.
If you'd like to work on a revamped debug console that works on major browsers and is standards compliant then I'd say go for it, sounds good |
|
Back to top |
|
6 ANUR Smarty Rookie
Joined: 06 May 2003 Posts: 23 Location: Lille, France
|
Posted: Thu Sep 09, 2004 11:55 am Post subject: |
|
|
I did a standard compliant version of the debug console bug but I face a problem. To be semantic the included templates list should be rendered as a unordered list but since the variable only gives the depth, I do not see a way to achieve that.
The semantic code would look like that :
Code: |
<ul>
<li>1st level template</li>
<li>1st level template
<ul>
<li>2nd level template</li>
</ul>
</li>
<li>1st level template</li>
<li>1st level template
<ul>
<li>2nd level template
<ul>
<li>3rd level template</li>
</ul>
</li>
</ul>
</li>
</ul>
|
Do you see a way to do that ? |
|
Back to top |
|
k-dub Smarty Rookie
Joined: 30 Sep 2004 Posts: 9 Location: Land of Opportunity, State of Confusion
|
Posted: Thu Sep 30, 2004 7:33 pm Post subject: |
|
|
I've been working with Smarty today with $smarty->debugging=true. I've run into a problem using the html_doctype plugin and Firefox. The current (2.6.5) Smarty debug.tpl file does not produce valid XHTML (<SCRIPT> should be lower case). I tried the modified version in this thread, and there are still XHTML-related problems. The output is after the final </html> tag and Firefox is giving me: Code: | XML Parsing Error: junk after document element |
It appears to me that this will never work unless it is above the </body> tag.
Am I missing something, or is this a true problem? _________________ rm -rf /bin/laden |
|
Back to top |
|
6 ANUR Smarty Rookie
Joined: 06 May 2003 Posts: 23 Location: Lille, France
|
Posted: Thu Sep 30, 2004 7:41 pm Post subject: |
|
|
You are right k-dub. I also noticed this problem but fixing it nicely would mean changing the way the debug console is handled by Smarty. I think it would be changed but it is not up to me to decide.
The better way I have found to fix this problem without modifying Smarty is to set debug to false and to use the {debug} tag in your templates. |
|
Back to top |
|
|