mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update debugging to expand array variables
This commit is contained in:
@@ -695,6 +695,8 @@ function smarty_func_assign_debug_info($args, &$smarty_obj) {
|
||||
|
||||
$included_templates = $smarty_obj->_smarty_debug_info;
|
||||
|
||||
$smarty_obj->assign("_debug_expand",$smarty_obj->_smarty_debug_expand);
|
||||
|
||||
$smarty_obj->assign("_debug_keys",array_keys($assigned_vars));
|
||||
$smarty_obj->assign("_debug_vals",array_values($assigned_vars));
|
||||
|
||||
@@ -702,6 +704,34 @@ function smarty_func_assign_debug_info($args, &$smarty_obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: smarty_func_debug_print_var
|
||||
Purpose: prints variable (or array) contents to the console
|
||||
\*======================================================================*/
|
||||
function smarty_mod_debug_print_var($var,$depth=0,$length=40) {
|
||||
if(is_array($var)) {
|
||||
$results = "<b>Array (".count($var).")</b>".'<br>\r'.$results;
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$return = smarty_mod_debug_print_var($curr_val,$depth+1);
|
||||
$results .= str_repeat(' ',$depth*2)."<b>$curr_key</b> => $return".'<br>\r';
|
||||
}
|
||||
return $results;
|
||||
} else {
|
||||
if(empty($var)) {
|
||||
return '<i>empty</i>';
|
||||
}
|
||||
if( strlen($var) > $length ) {
|
||||
$results = substr($var,0,$length-3).'...';
|
||||
} else {
|
||||
$results = $var;
|
||||
}
|
||||
$results = preg_replace("![\r\t\n]!"," ",$results);
|
||||
$results = htmlspecialchars($results);
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: smarty_func_overlib_init
|
||||
Purpose: initialize use of overlib
|
||||
|
@@ -161,7 +161,8 @@ class Smarty
|
||||
'count_characters' => 'smarty_mod_count_characters',
|
||||
'count_words' => 'smarty_mod_count_words',
|
||||
'count_sentences' => 'smarty_mod_count_sentences',
|
||||
'count_paragraphs' => 'smarty_mod_count_paragraphs'
|
||||
'count_paragraphs' => 'smarty_mod_count_paragraphs',
|
||||
'debug_print_var' => 'smarty_mod_debug_print_var'
|
||||
);
|
||||
|
||||
var $show_info_header = false; // display HTML info header at top of page output
|
||||
|
@@ -15,13 +15,13 @@
|
||||
{/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><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}){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>");
|
||||
_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><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</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 (outter 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><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></td><td>{if is_array($_debug_config_vals[config_vars])}<font color=green>Array</font> ({$_debug_config_vals[config_vars]|@count}){elseif empty($_debug_config_vals[config_vars])}<i>no value</i>{else}<font color=red>{$_debug_config_vals[config_vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"<i>empty</i>"}</font>{/if}</tt></td></tr>");
|
||||
_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}</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}
|
||||
|
@@ -161,7 +161,8 @@ class Smarty
|
||||
'count_characters' => 'smarty_mod_count_characters',
|
||||
'count_words' => 'smarty_mod_count_words',
|
||||
'count_sentences' => 'smarty_mod_count_sentences',
|
||||
'count_paragraphs' => 'smarty_mod_count_paragraphs'
|
||||
'count_paragraphs' => 'smarty_mod_count_paragraphs',
|
||||
'debug_print_var' => 'smarty_mod_debug_print_var'
|
||||
);
|
||||
|
||||
var $show_info_header = false; // display HTML info header at top of page output
|
||||
|
@@ -15,13 +15,13 @@
|
||||
{/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><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}){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>");
|
||||
_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><tt><font color=green>{$_debug_vals[vars]|@debug_print_var}</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 (outter 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><tt><font color=maroon>{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim}</font></td><td>{if is_array($_debug_config_vals[config_vars])}<font color=green>Array</font> ({$_debug_config_vals[config_vars]|@count}){elseif empty($_debug_config_vals[config_vars])}<i>no value</i>{else}<font color=red>{$_debug_config_vals[config_vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"<i>empty</i>"}</font>{/if}</tt></td></tr>");
|
||||
_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}</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}
|
||||
|
Reference in New Issue
Block a user