Initial use and Considerations for PHP Smarty Framework
1. What is a template engine
Two parts more concerned
1.1 is GUI (view, interface)--html CSS javascripte
1.2 is the business logic (PHP code)--php MYSQL
The template engine is a project developed using PHP
2.Smarty
2.1 Installation
1. Unzip, only use the Libs directory, need to use Smarty.class.php and plugins folder
2. Create folder: Templates and Template_c folder (default folder name)
3. Create a PHP file (see example)
Include "./libs/smarty.class.php";
Set the replacement content, set the display template
4. Access
2.2Smarty initialization
1. Initialization can modify the set value in Smarty.class.php
2. Initialize the PHP page when it is called
Problem solved: Warning:strftime () [Function.strftime]:
Date_default_timezone_set ("Asia/shanghai");
Include "./libs/smarty.class.php";
$TPL = new Smarty ();
Smarty Initialization
$tpl->template_dir= "./templates/";
$tpl->compile_dir= "./template_c/";
$TPL->left_delimiter= " ";
2.3Smarty Precautions for use
1. Find Resources (Css/js/image)
Resource files are placed in the corresponding resource location on the PHP page accessed (because the template is included in the PHP file when accessed)
2. When all display templates (or include) are specified, specify the base path in the Smarty template
3. When PHP references a smarty file outside the template directory, replace the Smarty initial file with an absolute path
Example code:
init.smarty.php
Template_dir=root. ". /templates/"; $tpl->compile_dir=root." /template_c/"; $tpl->left_delimiter=" "
;? >
mysmarty.php
Assign ("title", $title); $tpl->assign ("content", $content);//template file name can be arbitrarily defined: For example: MYSMARTY.TPL content is only HTML can be $tpl-> Display ("mysmarty.html");? >
Mysmarty.html
<!--{$title}-->