Home >Backend Development >PHP Tutorial >SMARTY Learning Notes_PHP Tutorial
You cannot learn PHP without mentioning SMARTY. As a famous template program, SMARTY naturally has its advantages. Below is a summary of my own learning experience!
=================================
first at Smarty.php.net Download the latest smarty
Put the libs folder in your WEB directory. I placed it under smarty. The directory is as follows: e:/smarty/libs
Create the following folder in the smarty directory:
templates (put your template files here, that is, tpl files)
configs
templates_c (automatically convert the compiled files into PHP and put them here)
cache
Then create index in the wwwroot directory .php:
include "smarty/libs/Smarty.class.php";
define('__SITE_ROOT', 'e:/smarty'); // No slash at the end
$tpl = new Smarty();
$tpl->template_dir = __SITE_ROOT . "/templates/";
$tpl->compile_dir = __SITE_ROOT . "/templates_c/";
$ tpl ->config_dir = __SITE_ROOT . "/configs/";
$tpl->cache_dir = __SITE_ROOT . "/cache/";
//$tpl->left_delimiter = '<{'; Can be changed as needed.
//$tpl->right_delimiter = '}>';
$tpl->assign('name','world!');
$tpl->display('index .tpl')
?>
Create index.tpl in the template directory: