Smarty technology learning, a bit of experience in modifying php templates, smarty, is the best name. with it, the configuration syntax is at the Cainiao level. if you don't say it, first list the one I used: smarty, the configuration syntax is Cainiao-level. if you do not have it, first list the items I used:
Php code:
If the template requires dynamic replacement, such as user login information, it is best to call js
The main parameter configurations are as follows:
Php code:
The commonly used two methods template_exists ($ f) are used to check whether the $ f template exists. Fetch () is used to return the output file of the template that has been signed by assign. it is useful when generating static pages.
Let's take a look at the description of smarty's own chm file. in addition to the basic syntaxes, it depends on your flexible use:
Parameter passing:
<{Includefile = "SiteAllTop.html" mysort = "0"}>
Obtain system parameters:
<{If $ MMSPAN [0] eq $ smarty. get. s}> selected <{/if}>
Clear all html formats:
<{$ OReDetail [6] | strip_tags}>
Note:
Php code:
Mathematical Operators and truncation:
Php code: {$ foo | truncate: "'$ fooTruncCount/$ barTruncFactor-1 '"}
Date format:
Php code:
OUTPUT:
Php code:
Regular expression usage:
Php code:
Format string:
{Textformatwrap = 40 indent = 4}
Date Comparison example:
Php code:<{If $ smarty. now | date_format: "% Y-% m-% d" eq $ MMSPAN [4] | date_format: "% Y-% m-% d"}>
<{/If}>
{* Use spaces to replace each carriage return, tab, and line break *}
{$ ArticleTitle}
{$ ArticleTitle | regex_replace :"/[
]/":" "}
Feb6, 2001
Tuesday, February6, 2001
14:33:00
Feb5, 2001
Monday, February5, 2001
14:33:00
{$ Smarty. now | date_format}
{$ Smarty. now | date_format: "% A, % B % e, % Y "}
{$ Smarty. now | date_format: "% H: % M: % S "}
{$ Yesterday | date_format}
{$ Yesterday | date_format: "% A, % B % e, % Y "}
{$ Yesterday | date_format: "% H: % M: % S "}
{* Smarty *}
{* Includetheheaderfilehere *}
{Includefile = "header. tpl "}
Include_once (IncludeFile. "/libs/Smarty. class. php ");
$ Tpl = newSmarty ();
$ Tpl-> caching = false; // True
// $ Tpl-> compile_check = true; // after confirmation, the template will not be compiled and changed to false.
$ Tpl-> template_dir = IncludeFile. "/templates/". Isite_tpl ."/";
$ Tpl-> compile_dir = IncludeFile. "/templates_c /";
$ Tpl-> config_dir = IncludeFile. "/configs /";
$ Tpl-> cache_dir = IncludeFile. "/cache /";
$ Tpl-> left_delimiter = '<{';
$ Tpl-> right_delimiter = '}> ';
/*
<{Foreach key = key item = MMSPANfrom = $ TSortUrl}>
<{If $ mysorteq $ key}>
Imgsrc = "images/sort _ <{$ key}> _ 1.gif" height =" 25 "border =" 0 "/>
<{Else}>
">. Gif" height = "25" border = "0"/>
<{/If}>
<{/Foreach}>