Basically Smarty's built-in regulator is already rich enough to meet simple requirements. To find out or add a new adjuster after you've learned about it
init.smarty.php
<?php
define ("ROOT", ".");
Problem solving: Warning:strftime () [Function.strftime]:
date_default_timezone_set ("Asia/shanghai");
Include ROOT. " /libs/smarty.class.php ";
$TPL = new Smarty ();
Smarty initialization
$tpl->template_dir=root. " /templates/";
$tpl->compile_dir=root. " /templates_c/";
The configuration file location
$tpl->config_dir=root. " /configs/";
$tpl->left_delimiter= "<!--{";
$TPL->right_delimiter= "}-->";
? >
mysmarty.php
<?php
/**
* *
* All use variables are based on the prefix and suffix
* variable adjuster
* You want to pass a string of uppercase, intercept, lowercase, then you need to pass three strings
* A variable adjuster can be used in a template using |functionname;
* functionname The first parameter is $STR, how to add other parameters can be added: To add parameters
* <!--{$str |tochange: "Lower"}-->
* <!--{$str |tochange: "Ten": "}-->"
* Two methods set
* 1. Write in PHP
* 2. Add modifier.tochange.php * 3 to the Plugins folder . Combination Adjuster * *
system-
supplied variable regulator (see Smarty API)
* Can own Baidu has been verified plug-ins
* *
can also find the format plug-in *
*
* */
//If the file load failed require will stop parsing PHP , while the include continues to execute
require ' init.smarty.php ';
$title = "This is a text title";
$str = "I am A-Bay boy!";
$tpl->assign ("title", $title);
$TPL->assign ("str", $STR);
$tpl->assign ("Strc", $title);
Template file name can be arbitrarily defined: For example: MYSMARTY.TPL only content is HTML can be
$tpl->display ("mysmarty.html");
>
Mysmarty.html
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Add the following file to the Smarty Plugin plugins folder for custom adjuster use
modifier.tocut.php
<?php
function Smarty_modifier_tocut ($str, $star, $len) {
$str =substr ($str, $star, $len);
return $str;
}
modifier.tochange.php
<?php
function Smarty_modifier_tochange ($str, $mod) {
switch ($mod) {case
"lower":
$str = Strtolower ($STR);
break;
Case "Upper":
$str =strtoupper ($STR);
break;
Case "a":
$str =ucfirst ($STR);
break;
return $str;
}