The first is the content of the show. tpl file, which is placed in the templates folder.
Smarty use caseSmarty Use Case <{* This is a comment *}>
* ***** Obtain the string *****
<{* Demonstrate obtaining strings * }>< {$ str}>
* ***** Integer *****
<{$ Integer}>
* ***** Decimal number *****
<{$ Float}>
* ***** Obtain the Boolean value *****
<{$ Bool}>
* ***** Retrieve the Index Array *****
Array Element 1-> <{$ arr [0]}>
Array element 2-> <{$ arr [1]}>
Array element 3-> <{$ arr [2]}>
* ***** Retrieve the joined array *****
Array Element 1-> <{$ arr2.city1}>
Array element 2-> <{$ arr2.city2}>
Array element 3-> <{$ arr2.city3}>
* ***** Retrieve a two-dimensional array *****
Element 1 of the first two-dimensional array-> <{$ arr3 [0] [0]}>
Element 2 of the first two-dimensional array-> <{$ arr3 [0] [1]}>
Element 3 of the first two-dimensional array->{$ arr3 [0] [2]}>
********************
Element 1 of the second array in a two-dimensional array-> <{$ arr3 [1] [0]}>
Element 2 of the second array in a two-dimensional array-> <{$ arr3 [1] [1]}>
Element 3 of the second array in a two-dimensional array->{$ arr3 [1] [2]}>
***** Retrieve two-dimensional joined array *****
Element 1 of the first two-dimensional array-> <{$ arr4 [0]. id}>
Element 2 of the first two-dimensional array-> <{$ arr4 [0]. username}>
Element 3 of the first two-dimensional array-> <{$ arr4 [0]. pwd}>
********************
Element 1 of the second array in a two-dimensional array-> <{$ arr4 [1]. id}>
Element 2 of the second two-dimensional array-> <{$ arr4 [1]. username}>
Element 3 of the second array in a two-dimensional array-> <{$ arr4 [1]. pwd}>
***** Retrieve the joined array in a two-dimensional array *****
Element 1 of the first two-dimensional array->{$ arr5.emp1. id}>
Element 2 of the first two-dimensional array->{$ arr5.emp1. username}>
Element 3 of the first two-dimensional array->{$ arr5.emp1. pwd}>
********************
Element 1 of the second array in a two-dimensional array->{$ arr5.emp2. id}>
Element 2 of the second two-dimensional array->{$ arr5.emp2. username}>
Element 3 of the second array in a two-dimensional array->{$ arr5.emp2. pwd}>
***** Retrieve the Index Array in a two-dimensional array *****
Element 1 of the first two-dimensional array-> <{$ arr6.emp1 [0]}>
Element 2 of the first two-dimensional array->{$ arr6.emp1 [1]}>
Element 3 of the first two-dimensional array->{$ arr6.emp1 [2]}>
********************
Element 1 of the second array in a two-dimensional array-> <{$ arr6.emp2 [0]}>
Element 2 of the second two-dimensional array->{$ arr6.emp2 [1]}>
Element 3 of the second array in a two-dimensional array->{$ arr6.emp2 [2]}>
* ***** Retrieve objects *****
Object Attributes $ dog-> name = <{$ dog-> name}>
Object Attributes $ dog-> age = <{$ dog-> age}>
Object Attributes $ dog-> color = <{$ dog-> color}>
Value of the attribute array of the object $ dog-> arr [0] = <{$ dog-> arr [0]}>
Value of the attribute array of the object $ dog-> arr [1] = <{$ dog-> arr [1]}>
Value of the attribute array of the object $ dog-> arr [2] = <{$ dog-> arr [2]}>
The content of the smarty. php file written by myself is as follows:
"'); $ Smarty = new Smarty (); $ smarty-> left_delimiter =" <{"; $ smarty-> right_delimiter ="}> "; $ smarty-> assign ("str", "hello"); $ smarty-> assign ("integer", 12); $ smarty-> assign ("float ", 100.0); $ smarty-> assign ("bool", true); // Index array $ arr = array ("Shanghai", "Beijing", "Tianjin "); $ smarty-> assign ("arr", $ arr); // associated array $ arr2 = array ('city1 '=> "Shanghai ", 'cit2' => "Beijing", 'city3' => "Tianjin"); $ smarty-> assign ("arr2", $ arr 2); // two-dimensional array $ arr3 = array ("Shanghai", "Beijing", "Tianjin"), array ("Xiaoqian", "Old demon ", "Cai Chen"); $ smarty-> assign ("arr3", $ arr3); $ arr4 = array ("id" => 1, "username" => "wang", "pwd" => "123"), array ("id" => 3, "username" => "xu ", "pwd" => "456"); $ smarty-> assign ("arr4", $ arr4 ); $ arr5 = array ('emp1' => array ("id" => 1, "username" => "wang", "pwd" => "123 "), 'emp2' => array ("id" => 3, "username" => "xu", "pwd" => "456"); $ smarty-> assign ("arr5", $ arr5); $ arr6 = array ('emp1' => array (1, "wang ", "123"), 'emp2' => array (3, "xu", "456"); $ smarty-> assign ("arr6", $ arr6 ); // allocate object class Dog {var $ name; var $ age; var $ color; var $ arr; function _ construct ($ name, $ age, $ color, $ arr) {$ this-> name = $ name; $ this-> age = $ age; $ this-> color = $ color; $ this-> arr = $ arr ;}} // instantiate the object $ dog = new Dog ("James", 11, "RED", $ arr); $ smarty -> Assign ("dog", $ dog); $ smarty-> display ("show. tpl");?>