This example describes the Smarty variable modifier usage in PHP. Share to everyone for your reference. The implementation methods are as follows:
test.php Code:
<?php
require ' libs/smarty.class.php ';//contains Smarty class library file
$smarty = new Smarty;//Create a newer Smarty object
$total = 12345; Assign value to $total
$smarty->assign ("Total", $total);//Assign value to variable in stencil
$formatted _total = Number_format ($total);// Format $total
$smarty->assign ("Formatted_total", $formatted _total);//Assign values to variables in the stencil
$smarty->display (' Test1.htm '); Display Page
?>
Test1.html Template code:
Compiled test.html.php code:
<?php/* Smarty version 2.6.22, created on 2009-03-19 14:37:39-compiled from
test1.htm */?>
<HTML>
test1.html templates can be rewritten as such test2.html:
The corresponding test.php code is changed to:
<?php
require ' libs/smarty.class.php ';//contains Smarty class library file
$smarty = new Smarty;//Create a newer Smarty object
$total = 12345;
$smarty->assign ("Total", $total); Assign values to variables in the template
$smarty->display (' test2.htm ');//Show Page
?>
Browser display:
Total is 12345
Formatted Total is 12,345
I hope this article will help you with your PHP program design.