Smarty technology learning, some experience in modifying PHP templates_PHP tutorial

WBOY
Release: 2016-07-13 17:29:38
Original
922 people have browsed it

Smarty is the most named, and its configuration syntax is all at the rookie level. There is no need to say, let’s list some of the ones I use:
<{foreach key=key item=MMSPAN from=$TSortUrl}>


< ;{if $mysort eq $key}>
img src="images/sort_<{$key}>_1.gif" height="25" border="0" />

<{else}>



<{/if}>

<{/foreach}> ;


If there is a need for dynamic replacement in the template, such as user login information, the best thing is to call js Mainly The parameter configuration is:

include_once(IncludeFile."/libs/Smarty.class.php");
$tpl = new Smarty();
$tpl->caching= false; //True turns on caching
//$tpl->compile_check=true;//Confirm that the template will no longer be compiled in the future, change it 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 = }>;
/*


Among them, the commonly used 2 methods
template_exists($f)
, used to detect whether $f template exists. fetch() is used to return the output file of the assigned template, which is very useful when generating static pages. Take a look at smarty’s own chm file description. In addition to the basic syntax, it depends on your flexible use:

Passing parameters:

<{include file="SiteAllTop.html" mysort ="0" }>

Get system parameters:

<{if $MMSPAN[0] eq $smarty.get.s}>selected<{/if}>
Clear all html formats:

<{$OReDetail[6]|strip_tags}>
Notes:
{* Smarty *}
{* include the header file here *}
{include file="header.tpl"}



Mathematical operators and interception:

{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}

Date formatting:
{$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"}

OUTPUT:

Feb 6, 2001
Tuesday, February 6, 2001
14:33:00
Feb 5, 2001
Monday, February 5, 2001
14:33:00

Regular use:
{* Replace each carriage return, tab, and line feed with a space *}
{$articleTitle}
{$articleTitle|regex_replace:"/[ ]/":" "}


Format string:


{textformat wrap=40 indent=4}

Date comparison example:
<{if $smarty.now|date_format:"%Y-%m-%d" eq $MMSPAN[4]|date_format:"%Y-%m-%d"}>

<{/if}>

http://www.bkjia.com/PHPjc/531662.html

truehttp: //www.bkjia.com/PHPjc/531662.htmlTechArticlesmarty, the most famous one, the configuration syntax used is all at the rookie level, there is no need to say, let’s list it first What I use: {foreachkey=keyitem=MMSPANfrom=$TSortUrl} tdalign="left"valign="bottom"hei...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template