First, know smarty
1 require_once("./smarty/libs/Smarty.class.php"); 2 $smarty = new Smarty(); 3 4 $smarty->assign("name", 'lxwwwih'); 5 6 $smarty->assign("age", 25); 7 8 $smarty->display("view.html");
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 姓名:{$name} 9 年龄:{$age} 10 </body> 11 </html>
Second, the configuration smarty
1, css the style body {backround-color: #fff}, there is a conflict
$smarty->left_delimiter = "<{";
$smarty->right_delimiter = "}>";
2, common configuration directory
① Set catalog view files
$ Smarty-> setTemplateDir ( "the new directory path");
$smarty->getTemplateDir();
1 require_once("./smarty/libs/Smarty.class.php"); 2 $smarty = new Smarty(); 3 4 $smarty->left_delimiter = "<{"; 5 $smarty->right_delimiter = "}>"; 6 7 $smarty->setTemplateDir("./App/Home/View/"); 8 9 print_r($smarty->getTemplateDir()); 10 11 $smarty->assign("name", 'lxwwwih'); 12 13 $smarty->assign("age", 25); 14 15 $smarty->display("view.html");
3, build directory and reading method is provided
$smarty->setCompileDir();$smarty->setConfigDir();
Three, Smarty variables in
1, Common variable values, strings, arrays,
2, get superglobal array
{$ Smarty.get.id} corresponding to the variable $ _GET array
{$ Smarty.post.id} corresponding to the variable $ _POST array
{$ Smarty.session.} Parameter value corresponding to the variable $ _SESSION array
3, to obtain a constant php
{$ Smarty.const. Constants}
{$smarty.const.PHP_INT_MAX}
Acquires a time stamp <{$ smarty.now}>