Odp: Re: Debug screen

From: Date: Thu, 20 Sep 2001 10:08:45 +0000
Subject: Odp: Re: Debug screen
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1493@lists.php.net to get a copy of this message
Witam > On Sun, Sep 16, 2001 at 01:56:35PM +0200, Micha? Sznajder wrote: > > I'm kind of new to Smarty but I want to contribute (perhaps) some code. At > > http://server1.fxmedia.com.pl/smarty.html you find > > modified screen of > > debug.tpl from standard distribution (1.4.4). My modification shows more > > specific information on arrays. Not only "Array (7)" but a complete 'tree'. > > I think it can help much. > could you send your debug.tpl? I was busy so I couldn't send it earlier. Modification is to part. First we have to modify debug.tpl : [.........] _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></td><td>{if is_array($_debug_vals[vars])}<font color=green>Array</font>({$_debug_vals[vars]|@count})<br> {$_debug_vals[vars]|@print_r} {elseif empty($_debug_vals[vars])}<i>no value</i>{else}<font color=red>{$_debug_vals[vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"<i>empty</i>"}</font>{/if}</tt></td></tr>"); {sectionelse} [............] I you compare this to original you see a new function print_r (look left from word "Array"). On the PHP side you have to use this code: <?php function smarty_print_r() { $arg_list = func_get_args(); $arg_num = func_num_args(); if($arg_num == 1) $ident = 0; else $ident = $arg_list[1]; $ret = array(); $arg_list = $arg_list[0]; foreach($arg_list as $key => $val) { if(is_array($val)) $val = "<font color=green>Array</font>". "<font color=black>(".count($val).")</font><br> ". smarty_print_r($val, $ident + 1); $ret[] = str_repeat("&nbsp;", 5 * $ident)."[$key] => <font color=red>$val</font>"; } return "<font color=black>".implode("<br>", $ret)."</font>"; } $smarty->register_modifier("print_r","smarty_print_r"); ?> It was a quick hack. I know it's not very good but it's quite sufficient for me. -- Pozdrawiam Michal "Misza" Sznajder [ http://www.fxmedia.com.pl/ ]

« previous php.smarty.general (#1493) next »