diff --git a/Smarty.addons.php b/Smarty.addons.php
index fe5cca90..aeaae0ad 100644
--- a/Smarty.addons.php
+++ b/Smarty.addons.php
@@ -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 = "Array (".count($var).")".'
\r'.$results;
+ foreach ($var as $curr_key => $curr_val) {
+ $return = smarty_mod_debug_print_var($curr_val,$depth+1);
+ $results .= str_repeat(' ',$depth*2)."$curr_key => $return".'
\r';
+ }
+ return $results;
+ } else {
+ if(empty($var)) {
+ return 'empty';
+ }
+ 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
diff --git a/Smarty.class.php b/Smarty.class.php
index 5df51053..d8ffd230 100644
--- a/Smarty.class.php
+++ b/Smarty.class.php
@@ -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
diff --git a/demo/templates/debug.tpl b/demo/templates/debug.tpl
index f303fb7f..0a7a42c2 100644
--- a/demo/templates/debug.tpl
+++ b/demo/templates/debug.tpl
@@ -15,13 +15,13 @@
{/section}
_smarty_console.document.write("
assigned template variables: |
");
{section name=vars loop=$_debug_keys}
- _smarty_console.document.write("{ldelim}${$_debug_keys[vars]}{rdelim} | {if is_array($_debug_vals[vars])}Array ({$_debug_vals[vars]|@count}){elseif empty($_debug_vals[vars])}no value{else}{$_debug_vals[vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"empty"}{/if} |
");
+ _smarty_console.document.write("{ldelim}${$_debug_keys[vars]}{rdelim} | {$_debug_vals[vars]|@debug_print_var} |
");
{sectionelse}
_smarty_console.document.write("no template variables assigned |
");
{/section}
_smarty_console.document.write("assigned config file variables (outter template scope): |
");
{section name=config_vars loop=$_debug_config_keys}
- _smarty_console.document.write("{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim} | {if is_array($_debug_config_vals[config_vars])}Array ({$_debug_config_vals[config_vars]|@count}){elseif empty($_debug_config_vals[config_vars])}no value{else}{$_debug_config_vals[config_vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"empty"}{/if} |
");
+ _smarty_console.document.write("{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim} | {$_debug_config_vals[config_vars]|@debug_print_var} |
");
{sectionelse}
_smarty_console.document.write("no config vars assigned |
");
{/section}
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 5df51053..d8ffd230 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -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
diff --git a/templates/debug.tpl b/templates/debug.tpl
index f303fb7f..0a7a42c2 100644
--- a/templates/debug.tpl
+++ b/templates/debug.tpl
@@ -15,13 +15,13 @@
{/section}
_smarty_console.document.write("assigned template variables: |
");
{section name=vars loop=$_debug_keys}
- _smarty_console.document.write("{ldelim}${$_debug_keys[vars]}{rdelim} | {if is_array($_debug_vals[vars])}Array ({$_debug_vals[vars]|@count}){elseif empty($_debug_vals[vars])}no value{else}{$_debug_vals[vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"empty"}{/if} |
");
+ _smarty_console.document.write("{ldelim}${$_debug_keys[vars]}{rdelim} | {$_debug_vals[vars]|@debug_print_var} |
");
{sectionelse}
_smarty_console.document.write("no template variables assigned |
");
{/section}
_smarty_console.document.write("assigned config file variables (outter template scope): |
");
{section name=config_vars loop=$_debug_config_keys}
- _smarty_console.document.write("{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim} | {if is_array($_debug_config_vals[config_vars])}Array ({$_debug_config_vals[config_vars]|@count}){elseif empty($_debug_config_vals[config_vars])}no value{else}{$_debug_config_vals[config_vars]|truncate:50|regex_replace:"![\r\t\n]!":" "|escape|default:"empty"}{/if} |
");
+ _smarty_console.document.write("{ldelim}#{$_debug_config_keys[config_vars]}#{rdelim} | {$_debug_config_vals[config_vars]|@debug_print_var} |
");
{sectionelse}
_smarty_console.document.write("no config vars assigned |
");
{/section}