commit updates, add debug template

This commit is contained in:
mohrt
2001-06-19 20:04:43 +00:00
parent 73b049acb7
commit 6af4598a2a
9 changed files with 471 additions and 17 deletions

5
NEWS
View File

@@ -1,10 +1,13 @@
- added regex_replace modifier, documented (Monte)
- added debugging console feature, documented (Monte)
- added custom function assign_debug_info, documented (Monte)
- added 'scope' attribute for {config_load}, 'global' is now deprecated but
is still supported. (Andrei)
- reduced template symbol table pollution by moving config array into the
class itself. (Andrei)
- fixed a bug with passing quoted arguments to modifiers inside {if}
statements. (Andrei, Sam Beckwith)
- added security features for third party template editing. (Monte)
- added security features for third party template editing, documented (Monte)
- added assign custom function, documented. (Monte)
- fixed bug with template header using version instead of _version. (Monte)
- fixed a problem with putting $ followed by numbers inside {strip} and

View File

@@ -177,6 +177,15 @@ function smarty_mod_replace($string, $search, $replace)
return str_replace($search, $replace, $string);
}
/*======================================================================*\
Function: smarty_mod_regex_replace
Purpose: regular epxression search/replace
\*======================================================================*/
function smarty_mod_regex_replace($string, $search, $replace)
{
return preg_replace($search, $replace, $string);
}
/*======================================================================*\
Function: smarty_mod_strip_tags
Purpose: strip html tags from text
@@ -598,6 +607,21 @@ function smarty_func_counter() {
return true;
}
/*======================================================================*\
Function: smarty_func_assign_debug_info
Purpose: assign debug info to the template
\*======================================================================*/
function smarty_func_assign_debug_info($args, &$smarty_obj) {
$assigned_vars = $smarty_obj->_tpl_vars;
ksort($assigned_vars);
$included_templates = $smarty_obj->_included_tpls;
sort($included_templates);
$smarty_obj->assign("_debug_keys",array_keys($assigned_vars));
$smarty_obj->assign("_debug_vals",array_values($assigned_vars));
$smarty_obj->assign("_debug_tpls",$included_templates);
return true;
}
/* vim: set expandtab: */
?>

View File

@@ -59,7 +59,7 @@ 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 $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array
// that are implicitly assigned
@@ -114,7 +114,7 @@ class Smarty
var $left_delimiter = '{'; // template tag delimiters.
var $right_delimiter = '}';
var $compiler_funcs = array(
);
@@ -124,7 +124,8 @@ class Smarty
'math' => 'smarty_func_math',
'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign'
'assign' => 'smarty_func_assign',
'assign_debug_info' => 'smarty_func_assign_debug_info'
);
var $custom_mods = array( 'lower' => 'strtolower',
@@ -136,6 +137,7 @@ class Smarty
'date_format' => 'smarty_mod_date_format',
'string_format' => 'smarty_mod_string_format',
'replace' => 'smarty_mod_replace',
'regex_replace' => 'smarty_mod_regex_replace',
'strip_tags' => 'smarty_mod_strip_tags',
'default' => 'smarty_mod_default',
'count_characters' => 'smarty_mod_count_characters',
@@ -145,6 +147,8 @@ class Smarty
);
var $show_info_header = false; // display HTML info header at top of page output
var $show_info_include = true; // display HTML comments at top & bottom of
// each included template
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
// Smarty to compile templates
@@ -166,6 +170,7 @@ class Smarty
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
var $_version = '1.4.2'; // Smarty version number
var $_extract = false; // flag for custom functions
var $_included_tpls = array(); // list of included templates
/*======================================================================*\
Function: Smarty
@@ -485,8 +490,10 @@ class Smarty
\*======================================================================*/
function fetch($tpl_file, $cache_id = null, $display = false)
{
global $HTTP_SERVER_VARS;
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
$this->_included_tpls[] = $tpl_file;
if ($this->caching) {
// cache name = template path + cache_id
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
@@ -528,18 +535,30 @@ class Smarty
} else {
$info_header = '';
}
// if we just need to display the results, don't perform output
// buffering - for speed
if ($display && !$this->caching) {
echo $info_header;
$this->_process_template($tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
} else {
ob_start();
echo $info_header;
$this->_process_template($tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
$results = ob_get_contents();
ob_end_clean();
}
@@ -557,6 +576,72 @@ class Smarty
}
}
/*======================================================================*\
Function: _display_debug_info
Purpose: display debugging information
\*======================================================================*/
function _display_debug_info()
{
asort($this->_debug_tpl);
reset($this->_debug_tpl);
ksort($this->_tpl_vars);
reset($this->_tpl_vars);
echo "<SCRIPT language=javascript>\n";
echo '_smarty_console = window.open("","console","width=500,height=600,resizable,scrollbars=yes"); ';
echo '_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>"); ';
echo "\n";
echo '_smarty_console.document.write("<b>included templates:</b><br>"); ';
echo "\n";
foreach ($this->_debug_tpl as $curr_tpl) {
echo '_smarty_console.document.write("<font color=blue>'.$curr_tpl.'</font><br>"); ';
echo "\n";
}
echo '_smarty_console.document.write("<br><b>assigned template variables:</b><br>"); ';
echo "\n";
echo '_smarty_console.document.write("<PRE>"); ';
echo "\n";
$search = array('!"!','![\r\t\n]!');
$replace = array("'",' ');
foreach ($this->_tpl_vars as $key => $val) {
echo '_smarty_console.document.write("<font color=red>{\$'.$key.'}</font> = <font color=blue>'.preg_replace($search,$replace,htmlspecialchars(substr($val,0,50))).'</font>';
if(is_array($val)) {
echo " (".count($val).")";
}
echo '<br>"); ';
if(is_array($val) && $this->debug_level > 2) {
$this->_print_debug_array($val,1);
}
}
echo '_smarty_console.document.write("</PRE>"); ';
echo "\n";
echo '_smarty_console.document.write("</BODY></HTML>"); ';
echo "\n";
echo '_smarty_console.document.close(); ';
echo "\n";
echo "</SCRIPT>\n";
}
/*======================================================================*\
Function: _print_debug_array
Purpose: display debugging information
\*======================================================================*/
function _print_debug_array($array,$level)
{
foreach($array as $key => $val) {
for($x=0; $x<$level; $x++) {
echo '_smarty_console.document.write("&nbsp;&nbsp;&nbsp;"); ';
echo "\n";
}
$search = array('!"!','![\r\t\n]!');
$replace = array("'",' ');
echo '_smarty_console.document.write("<font color=red>{\$'.$key.'}</font> = <font color=blue>'.preg_replace($search,$replace,htmlspecialchars(substr($val,0,50))).'</font><br>"); ';
echo "\n";
if(is_array($val)) {
$this->_print_debug_array($val,$level+1);
}
}
}
/*======================================================================*\
Function: _process_template()
Purpose:
@@ -751,8 +836,16 @@ class Smarty
array_unshift($this->_config, $this->_config[0]);
$this->_process_template($_smarty_include_tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$_smarty_include_tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$_smarty_include_tpl_file." -->\n";
}
$this->_included_tpls[] = $_smarty_include_tpl_file;
array_shift($this->_config);
}

21
demo/templates/debug.tpl Normal file
View File

@@ -0,0 +1,21 @@
{* Smarty *}
{assign_debug_info}
<SCRIPT language=javascript>
_smarty_console = window.open("","console","width=560,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>");
_smarty_console.document.write("<table border=0 width=100%>");
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates:</b></td></tr>");
{section name=templates loop=$_debug_tpls}
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt><font color=blue>{$_debug_tpls[templates]}</font></tt></td></tr>");
{/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>{$_debug_keys[vars]}</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>");
{/section}
_smarty_console.document.write("</table>");
_smarty_console.document.write("</BODY></HTML>");
_smarty_console.document.close();
</SCRIPT>

View File

@@ -1,2 +1,3 @@
{include file="debug.tpl"}
</BODY>
</HTML>

209
docs.sgml
View File

@@ -14,7 +14,7 @@
<address><email>andrei@php.net</email></address>
</affiliation>
</author>
<edition>Version 1.4.2</edition>
<edition>Version 1.4.3</edition>
<copyright><year>2001</year><holder>ispi of Lincoln, Inc.</holder></copyright>
</bookinfo>
<chapter>
@@ -436,16 +436,72 @@ chmod 700 cache
<link linkend="variable.modifiers">modifiers</link> instead.
</para>
</sect2>
<sect2 id="setting.security">
<title>$security</title>
<para>
$security true/false, default is false. Security is good for
situations when you have untrusted parties editing the templates
(via ftp for example) and you want to reduce the risk of system
security compromises through the template language. Turning on
security enforces the following rules to the template language,
unless specifially overridden with $security_settings:
</para>
<itemizedlist>
<listitem><para>If $php_handling is set to SMARTY_PHP_ALLOW, this is
implicitly changed to SMARTY_PHP_PASSTHRU</para></listitem>
<listitem><para>PHP functions are not allowed in IF statements,
except those specified in the $security_settings</para></listitem>
<listitem><para>templates can only be included from directories
listed in the $secure_dir array</para></listitem>
<listitem><para>local files can only be fetched from directories
listed in the $secure_dir array using {fetch}</para></listitem>
<listitem><para>{php}{/php} tags are not allowed</para></listitem>
<listitem><para>PHP functions are not allowed as modifiers, except
those specified in the $security_settings</para></listitem>
</itemizedlist>
<para>
NOTE: Security features were added to Smarty 1.4.3.
</para>
</sect2>
<sect2 id="setting.secure.dir">
<title>$secure_dir</title>
<para>
This is an array of all local directories that are considered
secure. {include} and {fetch} use this when security is enabled.
</para>
</sect2>
<sect2 id="setting.security.settings">
<title>$security_settings</title>
<para>
These are used to override or specify the security settings when
security is enabled. These are the possible settings:
</para>
<itemizedlist>
<listitem><para>PHP_HANDLING - true/false. If set to true, the
$php_handling setting is not checked for security.</para></listitem>
<listitem><para>IF_FUNCS - This is an array of the names of permitted
PHP functions in IF statements.</para></listitem>
<listitem><para>INCLUDE_ANY - true/false. If set to true, any
template can be included from the file system, regardless of the
$secure_dir list.</para></listitem>
<listitem><para>PHP_TAGS - true/false. If set to true, {php}{/php}
tags are permitted in the templates.</para></listitem>
<listitem><para>MODIFIER_FUNCS - This is an array of the names of permitted
PHP functions used as variable modifiers.</para></listitem>
</itemizedlist>
</sect2>
<sect2 id="setting.left.delimiter">
<title>$left_delimiter</title>
<para>
This is the left delimiter used by the template language. Default is "{".
This is the left delimiter used by the template language.
Default is "{".
</para>
</sect2>
<sect2 id="setting.right.delimiter">
<title>$right_delimiter</title>
<para>
This is the right delimiter used by the template language. Default is "}".
This is the right delimiter used by the template language.
Default is "}".
</para>
</sect2>
<sect2 id="setting.custom.funcs">
@@ -523,6 +579,27 @@ $smarty->assign("Address",$address);
// passing an associative array
$smarty->assign(array("city" => "Lincoln","state" => "Nebraska"));
</programlisting>
</example>
</sect2>
<sect2 id="api.assign.debug.info">
<title>assign_debug_info</title>
<para>
This is used to assign debugging data to the template. This is
used exlusively by the <link
linkend="chapter.debugging.console">debugging console</link>.
</para>
<example>
<title>assign</title>
<programlisting>
// passing name/value pairs
$smarty->assign("Name","Fred");
$smarty->assign("Address",$address);
// passing an associative array
$smarty->assign(array("city" => "Lincoln","state" => "Nebraska"));
</programlisting>
</example>
</sect2>
@@ -1620,13 +1697,32 @@ Intro = """This is a value that spans more
<entry><emphasis>n/a</emphasis></entry>
<entry>The name of the section to load</entry>
</row>
<row>
<entry>scope</entry>
<entry>string</entry>
<entry>no</entry>
<entry><emphasis>local</emphasis></entry>
<entry>
How the scope of the loaded variables are treated,
which must be one of local, parent or global. local
means variables are loaded into the local template
context. parent means variables are loaded into both
the local context and the parent template that called
it. global means variables are available to all
templates. NOTE: This was added to Smarty 1.4.3.
</entry>
</row>
<row>
<entry>global</entry>
<entry>boolean</entry>
<entry>No</entry>
<entry><emphasis>No</emphasis></entry>
<entry>Whether or not variables are global (visible to
parent templates)</entry>
<entry>
Whether or not variables are visible to the parent
template, same as scope=parent. NOTE: This attribute is
deprecated by the scope attribute, but still supported.
If scope is supplied, this value is ignored.
</entry>
</row>
</tbody>
</tgroup>
@@ -2565,7 +2661,10 @@ OUTPUT:
</informaltable>
<para>
assign is used for assigning template variables during the execution
of the template. assign was added to Smarty 1.4.3.
of the template.
</para>
<para>
NOTE: This was added to Smarty 1.4.3.
</para>
<example>
<title>assign</title>
@@ -3809,6 +3908,68 @@ OUTPUT:
Two Convicts Evade Noose, Jury Hung.
two convicts evade noose, jury hung.
</programlisting>
</example>
</sect2>
<sect2>
<title>regex_replace</title>
<informaltable frame=all>
<tgroup cols=3>
<colspec colname=param>
<colspec colname=type>
<colspec colname=required>
<colspec colname=default>
<colspec colname=desc>
<thead>
<row>
<entry>Parameter Position</entry>
<entry>Type</entry>
<entry>Required</entry>
<entry>Default</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>1</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>This is the regular expression to be replaced.</entry>
</row>
<row>
<entry>2</entry>
<entry>string</entry>
<entry>Yes</entry>
<entry><emphasis>n/a</emphasis></entry>
<entry>This is the string of text to replace with.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
A regular expression search and replace on a variable. Use the
syntax for preg_replace() from the PHP manual.
</para>
<para>
NOTE: This function was added to Smarty 1.4.3.
</para>
<example>
<title>regex_replace</title>
<programlisting>
{* replace each carriage return, tab &amp; new line with a space *}
{$articleTitle}
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
OUTPUT:
Infertility unlikely to
be passed on, experts say
Infertility unlikely to be passed on, experts say
</programlisting>
</example>
</sect2>
@@ -4142,6 +4303,42 @@ s m o k e r s a r e p. . .
</sect2>
</sect1>
</chapter>
<chapter id="chapter.debugging.console">
<title>Debugging Console</title>
<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
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.
</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"}
&lt;BODY&gt;
&lt;HTML&gt;
</programlisting>
</example>
</chapter>
<chapter>
<title>Troubleshooting</title>
<para></para>

View File

@@ -59,7 +59,7 @@ 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 $global_assign = array( 'HTTP_SERVER_VARS' => array( 'SCRIPT_NAME' )
); // variables from the GLOBALS array
// that are implicitly assigned
@@ -114,7 +114,7 @@ class Smarty
var $left_delimiter = '{'; // template tag delimiters.
var $right_delimiter = '}';
var $compiler_funcs = array(
);
@@ -124,7 +124,8 @@ class Smarty
'math' => 'smarty_func_math',
'fetch' => 'smarty_func_fetch',
'counter' => 'smarty_func_counter',
'assign' => 'smarty_func_assign'
'assign' => 'smarty_func_assign',
'assign_debug_info' => 'smarty_func_assign_debug_info'
);
var $custom_mods = array( 'lower' => 'strtolower',
@@ -136,6 +137,7 @@ class Smarty
'date_format' => 'smarty_mod_date_format',
'string_format' => 'smarty_mod_string_format',
'replace' => 'smarty_mod_replace',
'regex_replace' => 'smarty_mod_regex_replace',
'strip_tags' => 'smarty_mod_strip_tags',
'default' => 'smarty_mod_default',
'count_characters' => 'smarty_mod_count_characters',
@@ -145,6 +147,8 @@ class Smarty
);
var $show_info_header = false; // display HTML info header at top of page output
var $show_info_include = true; // display HTML comments at top & bottom of
// each included template
var $compiler_class = 'Smarty_Compiler'; // the compiler class used by
// Smarty to compile templates
@@ -166,6 +170,7 @@ class Smarty
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
var $_version = '1.4.2'; // Smarty version number
var $_extract = false; // flag for custom functions
var $_included_tpls = array(); // list of included templates
/*======================================================================*\
Function: Smarty
@@ -485,8 +490,10 @@ class Smarty
\*======================================================================*/
function fetch($tpl_file, $cache_id = null, $display = false)
{
global $HTTP_SERVER_VARS;
global $HTTP_SERVER_VARS, $QUERY_STRING, $HTTP_COOKIE_VARS;
$this->_included_tpls[] = $tpl_file;
if ($this->caching) {
// cache name = template path + cache_id
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
@@ -528,18 +535,30 @@ class Smarty
} else {
$info_header = '';
}
// if we just need to display the results, don't perform output
// buffering - for speed
if ($display && !$this->caching) {
echo $info_header;
$this->_process_template($tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
} else {
ob_start();
echo $info_header;
$this->_process_template($tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$tpl_file." -->\n";
}
$results = ob_get_contents();
ob_end_clean();
}
@@ -557,6 +576,72 @@ class Smarty
}
}
/*======================================================================*\
Function: _display_debug_info
Purpose: display debugging information
\*======================================================================*/
function _display_debug_info()
{
asort($this->_debug_tpl);
reset($this->_debug_tpl);
ksort($this->_tpl_vars);
reset($this->_tpl_vars);
echo "<SCRIPT language=javascript>\n";
echo '_smarty_console = window.open("","console","width=500,height=600,resizable,scrollbars=yes"); ';
echo '_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>"); ';
echo "\n";
echo '_smarty_console.document.write("<b>included templates:</b><br>"); ';
echo "\n";
foreach ($this->_debug_tpl as $curr_tpl) {
echo '_smarty_console.document.write("<font color=blue>'.$curr_tpl.'</font><br>"); ';
echo "\n";
}
echo '_smarty_console.document.write("<br><b>assigned template variables:</b><br>"); ';
echo "\n";
echo '_smarty_console.document.write("<PRE>"); ';
echo "\n";
$search = array('!"!','![\r\t\n]!');
$replace = array("'",' ');
foreach ($this->_tpl_vars as $key => $val) {
echo '_smarty_console.document.write("<font color=red>{\$'.$key.'}</font> = <font color=blue>'.preg_replace($search,$replace,htmlspecialchars(substr($val,0,50))).'</font>';
if(is_array($val)) {
echo " (".count($val).")";
}
echo '<br>"); ';
if(is_array($val) && $this->debug_level > 2) {
$this->_print_debug_array($val,1);
}
}
echo '_smarty_console.document.write("</PRE>"); ';
echo "\n";
echo '_smarty_console.document.write("</BODY></HTML>"); ';
echo "\n";
echo '_smarty_console.document.close(); ';
echo "\n";
echo "</SCRIPT>\n";
}
/*======================================================================*\
Function: _print_debug_array
Purpose: display debugging information
\*======================================================================*/
function _print_debug_array($array,$level)
{
foreach($array as $key => $val) {
for($x=0; $x<$level; $x++) {
echo '_smarty_console.document.write("&nbsp;&nbsp;&nbsp;"); ';
echo "\n";
}
$search = array('!"!','![\r\t\n]!');
$replace = array("'",' ');
echo '_smarty_console.document.write("<font color=red>{\$'.$key.'}</font> = <font color=blue>'.preg_replace($search,$replace,htmlspecialchars(substr($val,0,50))).'</font><br>"); ';
echo "\n";
if(is_array($val)) {
$this->_print_debug_array($val,$level+1);
}
}
}
/*======================================================================*\
Function: _process_template()
Purpose:
@@ -751,8 +836,16 @@ class Smarty
array_unshift($this->_config, $this->_config[0]);
$this->_process_template($_smarty_include_tpl_file, $compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_BEGIN: ".$_smarty_include_tpl_file." -->\n";
}
include($compile_path);
if($this->show_info_include) {
echo "\n<!-- SMARTY_END: ".$_smarty_include_tpl_file." -->\n";
}
$this->_included_tpls[] = $_smarty_include_tpl_file;
array_shift($this->_config);
}

21
templates/debug.tpl Normal file
View File

@@ -0,0 +1,21 @@
{* Smarty *}
{assign_debug_info}
<SCRIPT language=javascript>
_smarty_console = window.open("","console","width=560,height=600,resizable,scrollbars=yes");
_smarty_console.document.write("<HTML><TITLE>Smarty Debug Console</TITLE><BODY bgcolor=#ffffff>");
_smarty_console.document.write("<table border=0 width=100%>");
_smarty_console.document.write("<tr bgcolor=#cccccc><th colspan=2>Smarty Debug Console</th></tr>");
_smarty_console.document.write("<tr bgcolor=#cccccc><td colspan=2><b>included templates:</b></td></tr>");
{section name=templates loop=$_debug_tpls}
_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt><font color=blue>{$_debug_tpls[templates]}</font></tt></td></tr>");
{/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>{$_debug_keys[vars]}</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>");
{/section}
_smarty_console.document.write("</table>");
_smarty_console.document.write("</BODY></HTML>");
_smarty_console.document.close();
</SCRIPT>

View File

@@ -1,2 +1,3 @@
{include file="debug.tpl"}
</BODY>
</HTML>