diff --git a/NEWS b/NEWS index da7fb852..3751c4b8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - move $version to internal variable, remove from docs (Monte) - cleaned up compiled templates global scope by moving some variables into the class itself. (Andrei) - fixed a bug that would not allow referring to a section in the including diff --git a/Smarty.class.php b/Smarty.class.php index ac38551e..b46c537f 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -130,7 +130,6 @@ class Smarty 'count_paragraphs' => 'smarty_mod_count_paragraphs' ); - var $version = '1.4.1'; // Smarty version number var $show_info_header = false; // display HTML info header at top of page output var $compiler_class = 'Smarty_Compiler'; // the compiler class used by @@ -150,6 +149,7 @@ class Smarty var $_sections = array(); // keeps track of sections var $_conf_obj = null; // configuration object var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + var $_version = '1.4.1'; // Smarty version number /*======================================================================*\ diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 2b0853a2..1b8a8808 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -145,7 +145,7 @@ class Smarty_Compiler extends Smarty { } // put header at the top of the compiled template - $template_header = "version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; + $template_header = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; $template_header .= " compiled from ".$tpl_file." */ ?>\n"; $template_compiled = $template_header.$template_compiled; diff --git a/docs.sgml b/docs.sgml index f1b0ddcd..3f01662f 100644 --- a/docs.sgml +++ b/docs.sgml @@ -14,7 +14,7 @@
andrei@php.net
- Version 1.3.0 + Version 1.4.1 2001ispi of Lincoln, Inc. @@ -468,12 +468,6 @@ chmod 700 cache Smarty.addons.php. - - $version - - Current version of Smarty, used in info header. - - $show_info_header @@ -4155,6 +4149,93 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75 Tips & Tricks + + Blank Variable Handling + + There may be times when you want to print a default value for an empty + variable instead of printing nothing, such as printing "&nbsp;" so that + table backgrounds work properly. Many would use an {if} statement to + handle this, but there is a shorthand way with Smarty, using the + default variable modifier. + + +Printing &nbsp; when a variable is empty + + + +{* the long way *} + +{if $title eq ""} + &nbsp; +{else} + {$title} +{/if} + + +{* the short way *} + +{$title|default:"&nbsp;"} + + + + + + Passing variable title to header template + + When the majority of your templates use the same headers and footers, it + is common to split those out into their own templates and include them. + But what if the header needs to have a different title, depending on + what page you are coming from? You can pass the title to the header when + it is included. + + +Passing the title variable to the header template + + + +mainpage.tpl +------------ + +{include file="header.tpl" title="Main Page"} +{* template body goes here *} +{include file="footer.tpl"} + + +archives.tpl +------------ + +{config_load file="archive_page.conf"} +{include file="header.tpl" title=#archivePageTitle#} +{* template body goes here *} +{include file="footer.tpl"} + + +header.tpl +---------- +<HTML> +<HEAD> +<TITLE>{$title|default:"BC News"}</TITLE> +</HEAD> +<BODY> + + +footer.tpl +---------- +</BODY> +</HTML> + + + + + When the main page is drawn, the title of "Main Page" is passed to the + header.tpl, and will subsequently be used as the title. When the + archives page is drawn, the title will be "Archives". Notice in the + archive example, we are using a varible from the archives_page.conf + file instead of a hard coded variable. Also notice that "BC News" is + printed if the $title variable is not set, using the + default variable modifier. + + Dates diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index ac38551e..b46c537f 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -130,7 +130,6 @@ class Smarty 'count_paragraphs' => 'smarty_mod_count_paragraphs' ); - var $version = '1.4.1'; // Smarty version number var $show_info_header = false; // display HTML info header at top of page output var $compiler_class = 'Smarty_Compiler'; // the compiler class used by @@ -150,6 +149,7 @@ class Smarty var $_sections = array(); // keeps track of sections var $_conf_obj = null; // configuration object var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' + var $_version = '1.4.1'; // Smarty version number /*======================================================================*\ diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 2b0853a2..1b8a8808 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -145,7 +145,7 @@ class Smarty_Compiler extends Smarty { } // put header at the top of the compiled template - $template_header = "version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; + $template_header = "_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."\n"; $template_header .= " compiled from ".$tpl_file." */ ?>\n"; $template_compiled = $template_header.$template_compiled;