Analysis of the smarty variable modifier usage instance in php. Test. php code: 123456789? PhprequirelibsSmarty. class. php; contains the Smarty class library file $ smartynewSmarty; creates a new php smarty variable modifier usage instance for analysis
Test. php code:
|
1
2
3
4
5
6
7
8
9 |
Require 'libs/Smarty. class. php'; // contains the Smarty class library file
$ Smarty = new Smarty; // create a new Smarty object
$ Total = 12345; // assign a value to $ total
$ Smarty-> assign ("total", $ total); // assign values to variables in the template
$ Formatted_total = number_format ($ total); // format $ total
$ Smarty-> assign ("formatted_total", $ formatted_total); // assign values to variables in the template
$ Smarty-> display('test1.htm'); // Display Page
?>
|
Code of the test1.html template:
|
1
2
3
4
5
6
7
8
9 |
Smarty Test
Total is {$ total}
Formatted Total is {$ formatted_total}
|
Compiled test.html. php code:
|
1
2
3
4
5
6
7
8
9
10
11
12
13 |
Compiled from test1.htm */?>
Smarty Test
Total is _ Tpl_vars ['total'];?>
Formatted Total is _ Tpl_vars ['formatted _ total'];?>
|
The test1.html template can be rewritten as test2.html:
|
1
2
3
4
5
6
7
8
9 |
Smarty Test
Total is {$ total}
Formatted Total is {$ total | number_format}
|
The corresponding test. php code is changed:
|
1
2
3
4
5
6
7 |
Require 'libs/Smarty. class. php'; // contains the Smarty class library file
$ Smarty = new Smarty; // create a new Smarty object
$ Total = 12345;
$ Smarty-> assign ("total", $ total); // assign values to variables in the template
$ Smarty-> display('test2.htm'); // Display Page
?>
|
Browser display:
Total is 12345
Formatted Total is 12,345
I hope this article will help you with php programming.
Example test. php code: 1 2 3 4 5 6 7 8 9? Php require 'libs/Smarty. class. php'; // contains the Smarty class library file $ smarty = new Smarty; // create a new...