This article illustrates the simple configuration and usage of smarty templates. Share to everyone for your reference, specific as follows:
Create the Templates,templates_c,configs,cache directory in the Smarty directory. For Smarty to compile and cache.
Set up the smarty_inc.php file to configure the Smarty as follows:
<?php
include_once ("./smarty/smarty.class.php");//containing smarty class file
$smarty = new Smarty ();//Create Smarty Instance object $ Smarty
$smarty->caching=false;//development is not recommended to open caching
$smarty->template_dir= "./templates"; Set the template directory
$smarty->compile_dir= "./templates_c"; Sets 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 ("Dingqing", "Dongdanfeng", "couple");
$smarty->assign ("name", $val);
$smarty->display ("index.html");
? >
Create a index.html template under Templates:
Well, that's it, it's that simple.
More about Smarty related content to view the site topics: "Smarty Template Primer Tutorial", "PHP Template Technology Summary", "PHP based on the PDO Operation database Skills summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", " Introduction to PHP Basic Grammar, "Introduction to PHP object-oriented programming", "PHP string (String) Usage Summary", "Php+mysql Database Operations Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on Smarty template.