Simple configuration and usage examples of the Smarty template, and examples of the smarty Template
This document describes the simple configuration and usage of the Smarty template. We will share this with you for your reference. The details are as follows:
Create the templates, templates_c, configs, and cache directories in the Smarty directory. So that Smarty can be compiled and cached.
Create a smarty_inc.php file and configure smarty as follows:
<? Phpinclude_once (". /smarty/Smarty. class. php "); // contains the smarty class file $ smarty = new Smarty (); // creates a smarty Instance Object $ smarty-> caching = false; // It is not recommended to enable cache $ smarty-> template_dir = ". /templates "; // set the template directory $ smarty-> compile_dir = ". /templates_c "; // set the compilation directory $ smarty-> cache_dir = ". /cache "; // cache folder $ smarty-> cache_lifetime = 60; $ smarty-> left_delimiter =" <{"; // left delimiter $ smarty-> right_delimiter = "}>"; // right delimiter?>
Line Test: Create the index. php file in the root directory:
<? Php include ("smarty_inc.php"); $ val = array ("ding Qing", "Dong Danfeng", "couples"); $ smarty-> assign ("name ", $ val); $ smarty-> display ("index.html");?>
Create an index.html Template under templates:
<Html>
Well, it's just that simple.