diff --git a/Smarty.class.php b/Smarty.class.php index 86376439..97520443 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -59,7 +59,10 @@ class Smarty var $template_dir = './templates'; // name of directory for templates var $compile_dir = './templates_c'; // name of directory for compiled templates var $config_dir = './configs'; // directory where config files are located - + + var $debugging = false; // enable debugging console true/false + var $debug_tpl = 'file:debug.tpl'; // path to debug console template + var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) ); // variables from the GLOBALS array // that are implicitly assigned @@ -516,9 +519,15 @@ class Smarty } if ($display) { echo $results; + if ($this->debugging) { echo $this->_generate_debug_output(); } return; } else { - return $results; + if ($this->debugging) { + $debug_output = $this->_generate_debug_output(); + return $results.$debug_output; + } else { + return $results; + } } } } @@ -573,16 +582,43 @@ class Smarty $this->_write_file($cache_file, $results, true); $results = $this->_process_cached_inserts($results); } - + if ($display) { if (isset($results)) { echo $results; } + if ($this->debugging) { echo $this->_generate_debug_output(); } return; } else { - if (isset($results)) { return $results; } + if (isset($results)) { + if ($this->debugging) { + $debug_output = $this->_generate_debug_output(); + return $results.$debug_output; + } else { + return $results; + } + } } } - +/*======================================================================*\ + Function: _generate_debug_output() + Purpose: generate debug output +\*======================================================================*/ + +function _generate_debug_output() { + ob_start(); + $this->_process_template($this->debug_tpl, $compile_path); + if ($this->show_info_include) { + echo "\n\n"; + } + include($compile_path); + if ($this->show_info_include) { + echo "\n\n"; + } + $results = ob_get_contents(); + ob_end_clean(); + return $results; +} + /*======================================================================*\ Function: _process_template() Purpose: diff --git a/demo/index.php b/demo/index.php index 9b751fc5..5acebb36 100644 --- a/demo/index.php +++ b/demo/index.php @@ -5,6 +5,7 @@ require("Smarty.class.php"); $smarty = new Smarty; $smarty->compile_check = true; +$smarty->debugging = true; $smarty->assign("now", time()); diff --git a/demo/templates/footer.tpl b/demo/templates/footer.tpl index 25dcaeaf..e04310fd 100644 --- a/demo/templates/footer.tpl +++ b/demo/templates/footer.tpl @@ -1,3 +1,2 @@ -{include file="debug.tpl"} diff --git a/docs.sgml b/docs.sgml index e05e57a2..d45b3b6f 100644 --- a/docs.sgml +++ b/docs.sgml @@ -286,6 +286,29 @@ chmod 700 cache the web server document root. + + $debugging + + This enables the debugging console. + The console is a javascript window that informs you of the + included templates and assigned variables for the current + template page. + + + NOTE: This was added to Smarty 1.4.3. + + + + $debug_tpl + + This is the name of the template file used for the debugging + console. + + + NOTE: This was added to Smarty 1.4.3. + + $global_assign @@ -4308,36 +4331,23 @@ s m o k e r s a r e p. . . There is a dubugging console included with Smarty. The console informs you of all the included templates and assigned variables for the current - invocation of the template, very useful information during development! A - template named "debug.tpl" is included with the distribution of Smarty. Put - this template where it can be included from a template within your - application. Include the template somewhere toward the bottom of the page. - If you have a footer template, this would be an excellent place to include - debug.tpl since it will automatically be included at the bottom of every - page that uses that footer. When you load the page, a javascript console + invocation of the template. A template named "debug.tpl" is included with + the distribution of Smarty. Set $debugging to true in Smarty and, if needed, + set $debug_tpl to the template resource path for debug.tpl (this is in + $template_dir by default.) When you load the page, a javascript console window should pop up and give you the names of all the included templates and assigned variables for the current page. To disable the debugging - console, simply remove the include statement from your template. + console, set $debugging to false. + + + TECHNICAL NOTE: The debugging console should be completely transparent to + your application. It is a set of javascript statements added to the very + bottom of the generated template. Debug data is not cached and is not + included in the output of the debug console. NOTE: This feature was added to Smarty 1.4.3. - -Including Debugging Console - - -footer.tpl ----------- - -{* We will include the debugging console in the footer template. *} -{* debug.tpl is in our default template directory. *} - -{include file="debug.tpl"} -<BODY> -<HTML> - - - Troubleshooting diff --git a/index.php b/index.php index 9b751fc5..5acebb36 100644 --- a/index.php +++ b/index.php @@ -5,6 +5,7 @@ require("Smarty.class.php"); $smarty = new Smarty; $smarty->compile_check = true; +$smarty->debugging = true; $smarty->assign("now", time()); diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 86376439..97520443 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -59,7 +59,10 @@ class Smarty var $template_dir = './templates'; // name of directory for templates var $compile_dir = './templates_c'; // name of directory for compiled templates var $config_dir = './configs'; // directory where config files are located - + + var $debugging = false; // enable debugging console true/false + var $debug_tpl = 'file:debug.tpl'; // path to debug console template + var $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' ) ); // variables from the GLOBALS array // that are implicitly assigned @@ -516,9 +519,15 @@ class Smarty } if ($display) { echo $results; + if ($this->debugging) { echo $this->_generate_debug_output(); } return; } else { - return $results; + if ($this->debugging) { + $debug_output = $this->_generate_debug_output(); + return $results.$debug_output; + } else { + return $results; + } } } } @@ -573,16 +582,43 @@ class Smarty $this->_write_file($cache_file, $results, true); $results = $this->_process_cached_inserts($results); } - + if ($display) { if (isset($results)) { echo $results; } + if ($this->debugging) { echo $this->_generate_debug_output(); } return; } else { - if (isset($results)) { return $results; } + if (isset($results)) { + if ($this->debugging) { + $debug_output = $this->_generate_debug_output(); + return $results.$debug_output; + } else { + return $results; + } + } } } - +/*======================================================================*\ + Function: _generate_debug_output() + Purpose: generate debug output +\*======================================================================*/ + +function _generate_debug_output() { + ob_start(); + $this->_process_template($this->debug_tpl, $compile_path); + if ($this->show_info_include) { + echo "\n\n"; + } + include($compile_path); + if ($this->show_info_include) { + echo "\n\n"; + } + $results = ob_get_contents(); + ob_end_clean(); + return $results; +} + /*======================================================================*\ Function: _process_template() Purpose: diff --git a/templates/footer.tpl b/templates/footer.tpl index 25dcaeaf..e04310fd 100644 --- a/templates/footer.tpl +++ b/templates/footer.tpl @@ -1,3 +1,2 @@ -{include file="debug.tpl"}