When learning PHP, SMARTY must be mentioned. As a famous template program, SMARTY naturally has its advantages. Below is my summary of my own learning experience!
=====================================
Download the latest smarty first
Put the libs folder in your WEB directory. I put it in smarty. The directory situation is as follows: e:/smarty/libs
Create the following folder in the smarty directory:
templates (put your template file here, i.e. tpl file)
configs
templates_c (automatically convert the compiled file to PHP and put it here)
cache
Then create it in the wwwroot directory:
<?php
include "smarty/libs/";
define('__SITE_ROOT', 'e:/smarty'); // There was no diagonal line in 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('')
?>
Create in the template directory:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
hello,{$name}~.
</body>
</html>
Then hello,world!~ is displayed locally.
=====================================
Download the latest smarty first
Put the libs folder in your WEB directory. I put it in smarty. The directory situation is as follows: e:/smarty/libs
Create the following folder in the smarty directory:
templates (put your template file here, i.e. tpl file)
configs
templates_c (automatically convert the compiled file to PHP and put it here)
cache
Then create it in the wwwroot directory:
<?php
include "smarty/libs/";
define('__SITE_ROOT', 'e:/smarty'); // There was no diagonal line in 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('')
?>
Create in the template directory:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
hello,{$name}~.
</body>
</html>
Then hello,world!~ is displayed locally.