Smarty installation and example, and smarty installation example. Smarty installation and example. smarty installation environment: smarty1.download the latest smartypackage at www.smarty.netdownload. select zips for Windows and tar.gz for Linux. Take windows as an example, and install smarty.
Environment:
Smarty
1. download the latest smartypackage at http://www.smarty.net/download. for Windows, select zips and linuxto select tar.gz. Take windows as an example. download and decompress the package, for example, f: \ smarty.
2. copy the lib directory in the extracted smarty directory to test and rename it as smarty. Create the tpls directory under the test directory, and create the templates, templates_c, configs, and cache directories under the tpls Directory. these directories are template directories (required ), resolution Directory (required), configuration Directory (optional), cache Directory (optional ),
The php code of smarty is the same level as the four directories, and the html code is stored in templates.
The directory tree is as follows:
Code section:
1. create main. php without bom in UTF-8 in test/smarty and configure some member attributes of smarty.
1
Template_dir = SMARTY_ROOT. "/templates/"; // set the template file storage directory 6 $ tpl-> compile_dir = SMARTY_ROOT. "/templates_c/"; // Set the directory where the compiled files are stored. 7 $ tpl-> config_dir = SMARTY_ROOT. "/configs/"; // Set the configuration file storage directory 8 $ tpl-> cache_dir = SMARTY_ROOT. "/cache/"; // Set the cache file storage directory 9 $ tpl-> caching = 1; // enable cache 10 $ tpl-> cache_lifetime = 60*60*24; // The validity period is 11 $ tpl-> left_delimiter = '['; // the left and right Terminator of the smarty Language 12 $ tpl-> right_delimiter = ']'; 13?>
We know that braces are the default delimiters of smarty, but they may conflict with javascript, css, and so on. So here we set them to [and].
2. create an html. tpl template file under test/tpls/templates, that is, add the smarty variable to html. The template is equivalent to the presentation layer.
The code for html. tpl is as follows:
1 2 3
4 5 [$title] 6 7 8 9 [$content]10 11
3. create smarty. php in the "test" directory. the file is equivalent to the driver layer. assign a value to the variables in the above presentation layer and then display them.
The code for smarty. php is as follows:
1
Assign ("title", "late"); 4 $ tpl-> assign ("content", "$500! "); 5 $ tpl-> display (" tpls/templates/html. tpl "); 6?>
4. run smarty. php in the browser.
Environment: smarty 1. download the latest smartypackage at http://www.smarty.net/download. in windows, select zips, and in Linux, select tar.gz. Take windows as an example...