mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
moved debug logic into Smarty completely, created flags for it
This commit is contained in:
@@ -60,6 +60,9 @@ class Smarty
|
||||
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,12 +519,18 @@ class Smarty
|
||||
}
|
||||
if ($display) {
|
||||
echo $results;
|
||||
if ($this->debugging) { echo $this->_generate_debug_output(); }
|
||||
return;
|
||||
} else {
|
||||
if ($this->debugging) {
|
||||
$debug_output = $this->_generate_debug_output();
|
||||
return $results.$debug_output;
|
||||
} else {
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_conf_obj === null) {
|
||||
/* Prepare the configuration object. */
|
||||
@@ -576,12 +585,39 @@ class Smarty
|
||||
|
||||
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<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
|
||||
}
|
||||
include($compile_path);
|
||||
if ($this->show_info_include) {
|
||||
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
|
||||
}
|
||||
$results = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $results;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _process_template()
|
||||
|
@@ -5,6 +5,7 @@ require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->compile_check = true;
|
||||
$smarty->debugging = true;
|
||||
|
||||
$smarty->assign("now", time());
|
||||
|
||||
|
@@ -1,3 +1,2 @@
|
||||
{include file="debug.tpl"}
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
58
docs.sgml
58
docs.sgml
@@ -286,6 +286,29 @@ chmod 700 cache
|
||||
the web server document root.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.debugging">
|
||||
<title>$debugging</title>
|
||||
<para>
|
||||
This enables the <link
|
||||
linkend="chapter.debugging.console">debugging console</link>.
|
||||
The console is a javascript window that informs you of the
|
||||
included templates and assigned variables for the current
|
||||
template page.
|
||||
</para>
|
||||
<para>
|
||||
NOTE: This was added to Smarty 1.4.3.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.debug.tpl">
|
||||
<title>$debug_tpl</title>
|
||||
<para>
|
||||
This is the name of the template file used for the debugging
|
||||
console.
|
||||
</para>
|
||||
<para>
|
||||
NOTE: This was added to Smarty 1.4.3.
|
||||
</para>
|
||||
</sect2>
|
||||
<sect2 id="setting.global.assign">
|
||||
<title>$global_assign</title>
|
||||
<para>
|
||||
@@ -4308,36 +4331,23 @@ s m o k e r s a r e p. . .
|
||||
<para>
|
||||
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.
|
||||
</para>
|
||||
<para>
|
||||
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.
|
||||
</para>
|
||||
<para>
|
||||
NOTE: This feature was added to Smarty 1.4.3.
|
||||
</para>
|
||||
<example>
|
||||
<title>Including Debugging Console</title>
|
||||
<programlisting>
|
||||
|
||||
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>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</chapter>
|
||||
<chapter>
|
||||
<title>Troubleshooting</title>
|
||||
|
@@ -5,6 +5,7 @@ require("Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
|
||||
$smarty->compile_check = true;
|
||||
$smarty->debugging = true;
|
||||
|
||||
$smarty->assign("now", time());
|
||||
|
||||
|
@@ -60,6 +60,9 @@ class Smarty
|
||||
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,12 +519,18 @@ class Smarty
|
||||
}
|
||||
if ($display) {
|
||||
echo $results;
|
||||
if ($this->debugging) { echo $this->_generate_debug_output(); }
|
||||
return;
|
||||
} else {
|
||||
if ($this->debugging) {
|
||||
$debug_output = $this->_generate_debug_output();
|
||||
return $results.$debug_output;
|
||||
} else {
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_conf_obj === null) {
|
||||
/* Prepare the configuration object. */
|
||||
@@ -576,12 +585,39 @@ class Smarty
|
||||
|
||||
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<!-- SMARTY_BEGIN: ".$this->debug_tpl." -->\n";
|
||||
}
|
||||
include($compile_path);
|
||||
if ($this->show_info_include) {
|
||||
echo "\n<!-- SMARTY_END: ".$this->debug_tpl." -->\n";
|
||||
}
|
||||
$results = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $results;
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _process_template()
|
||||
|
@@ -1,3 +1,2 @@
|
||||
{include file="debug.tpl"}
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
Reference in New Issue
Block a user