In order to more convenient use Smarty later, we can "load Smarty template engine", "Establish Smarty object", "Set parameters of Smarty object" Three steps into a common PHP file, in the future where we need to use the place we directly reuqire, you can, For example:
1. Establish a main.php
Include smarty/smarty.class.php;
The next time you migrate, you only need to change the root pointing location ~
Const DIR_SEP = directory_separator;
Define (ROOT, D:. Dir_sep._php_test.dir_sep. TEST2.DIR_SEP); $TPL = new Smarty ();
$tpl->template_dir = ROOT.templates.DIR_SEP;
$tpl->complie_dir = ROOT.templates_c.DIR_SEP;
$tpl->config_dir = ROOT.configs.DIR_SEP;
$tpl->cache_dir = ROOT.cache.DIR_SEP;
$tpl->left_delimiter = <{;
$tpl->right_delimiter =}>;
?>
Note 1: Why use directory_separator here? (Click to view)
Note 2:left_delimiter and Right_delimiter are left and right terminator variables, which can be defined here as other strings (the default is {}).
2. Under Templates, create a new test.htm
<{$title}>
<{$content}>
3. Call the template page to populate the title and content with a new test_smarty_1.php
Require main.php;
$tpl->assign (title, New Message);
$tpl->assign (content, this is Test smarty!);
$tpl->display (test.htm);
?>
Can also be written like this
Require main.php;
$TPL->assign (Array (title=>newmessage, Content=>this is Test smarty!));
$tpl->display (test.htm);
?>
Output Result:
Page Title display: Newmessage
Page content display: This is Test smarty!
http://www.bkjia.com/PHPjc/478801.html www.bkjia.com true http://www.bkjia.com/PHPjc/478801.html techarticle in order to use Smarty more conveniently later, we can put "load Smarty template engine", "Establish Smarty object", "Set parameters of Smarty object" Three steps to a public ...