Examples of this article describe the use of smarty variables. Share to everyone for your reference, as follows:
1. Variables assigned from PHP
The variable that is assigned from PHP is called with a "$" symbol before it. (Same as PHP)
This is also true for variables that are assigned by the Assign function in the calling template. (also called by the $ plus variable name)
Example:
index.php:
$smarty = new Smarty; $smarty->assign (' FirstName ', ' Doug '); $smarty->assign (' lastlogindate ', ' january11th, 2001 ') ); $smarty->display (' Index.tpl ');
INDEX.TPL:
Hello {$firstname}, glad to couldmake it.Your Last login is on {$lastLoginDate}.
Output:
Hello Doug, glad to see your could make it.Your last login is on January 11th, 2001.
2. Variables read from the configuration file
The variables in the configuration file need to be called by using two "#" or smarty reserved variables $smarty. config.
The second syntax is useful when a variable is enclosed in quotation marks as a property value.
(for example {include file= "#includefile #"} so that #includefile# will be treated as a character, not a profile variable, but it can be represented as {include file= "' $ Smarty.config.includefile ' "} Do not forget to add ')
Example:
Foo.conf:
PageTitle = "This is Mine" Bodybgcolor = "#eeeeee" tablebordersize = "3" Tablebgcolor = "#bbbbbb" Rowbgcolor = "#cccccc"
INDEX.TPL:
{config_load file= "foo.conf"}{#pageTitle #}
INDEX.TPL:
{config_load file= "foo.conf"}{$smarty. Config.pagetitle}
Both of these template formulations are output:
This is mine
Configuration file variables can only be used after they have been loaded.
More interested in smarty related content readers can view the topic: "Smarty Template Primer Basic Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " PHP Basic Grammar Introductory tutorial, PHP Object-oriented Programming primer, PHP string usage Summary, PHP+MYSQL database Operations Primer and PHP Common database operations Tips Summary
It is hoped that this article will be helpful to everyone based on smarty template PHP program design.