Smarty Quick Start 2. To make it easier to use smarty, we can put the three steps "loading the Smarty template engine", "creating a Smarty object", and "setting the parameters of a Smarty object" in a public way to make it easier to use smarty in the future, we can put the three steps "loading the Smarty template engine", "creating a Smarty object", and "setting the parameters of a Smarty object" in a public php file, in the future, we can reuqire it directly, for example:
1. create a main. php
Include smarty/Smarty. class. php;
// The next time the program is transplanted, you only need to modify the ROOT point 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 is DIRECTORY_SEPARATOR used here? (Click to view details)
Note 2: left_delimiter and right_delimiter are left and right Terminator variables, which can be defined as other strings (default {}).
2. create a new test.htm under templates.
<{$ Title}>
<{$ Content}>
3. call the template page to fill in the title and content, and create 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 );
?>
You can also write it 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
This is test smarty!
The following three steps are taken: Create a Smarty object and set the parameters of a Smarty object...