The examples in this article describe the use of smarty variables. Share to everyone for your reference, specific as follows:
1. Variables assigned from PHP
Calling variables assigned from PHP requires the "$" symbol before it. (Like PHP)
The same is true for variables that are assigned to the Assign function within the calling template. (also called with $ 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.
<p>
Your Last login is on {$lastLoginDate}.
Output:
Hello Doug, glad to the could make it.
<p>
Your Last login is on January 11th, 2001.
2. Variables read from the configuration file
Variables in the configuration file need to be invoked by using two "#" or smarty reserved variables $smarty. config.
The second syntax is useful when a variable is a property value and is enclosed in quotes.
For example {include file= "#includefile #"} So #includefile# will be treated as a character instead of a configuration file variable, but you can say {include file= "' $ Smarty.config.includefile ' "} Don't 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"}
INDEX.TPL:
{config_load file= "foo.conf"}
Both types of template writing are output:
Configuration file variables can only be used after they have been loaded.
More interested in smarty related content readers can view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on PDO Operation Database Skills summary", "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on Smarty template.