Left and right boundary characters. the default value is {}, but it is easy to conflict with JavaScript in actual application.
Include_once ("Smarty/Smarty. class. php "); // contains the smarty class file $ smarty = new Smarty (); // creates a smarty instance object $ smarty-> config_dir =" Smarty/Config_File.class.php "; // Directory variable $ smarty-> caching = false; // whether to use cache. during project debugging, it is not recommended to enable cache $ smarty-> template_dir = ". /templates "; // set the template directory $ smarty-> compile_dir = ". /templates_c "; // Set the compilation directory $ smarty-> cache_dir = ". /smarty_cache "; // cache folder // -------------------------------------------------------- // left and right bounders. the default value is {}, however, it is easy to conflict with JavaScript in actual applications. // ------------------------------------------------ $ smarty-> left_delimiter = "{"; $ smarty-> right_delimiter = "}";
Variable operators of the PHP template engine Smarty
1.Touch Version receive array display
{Section name = I loop = $ content}
{$ Content [I]. name}
{Sectionelse}
No
{/Section}
2.How to use SmartyVariable operators
The syntax uses "|" to apply the variable operator. multiple parameters are separated ":".
Capitalize [Uppercase letters] e. g: {$ content | capitalize}
Count_characters [Count of characters] e. g: {$ content | count_characters}
Cat [Connection string] e. g: {$ content | cat: $ title }:Number connection
Count_paragraphs [Calculate the number of paragraphs] e. g: {$ content | count_paragraphs}
Count_sentences [Calculate the number of periods] e. g: {$ content | count_sentences}
Count_words [Count of words] e. g: {$ content | count_words}
Date_format [Time format] e. g: {$ content | date_format: "% Y-% m-% d "}
Default [Default] e. g: {$ content | default: "no content}
Escape [Transcoding] e. g: {$ content | escape}
Indent [Indent] e. g: {$ content | indent: 10 :''}10 characters indented, replaced by spaces
Lower [Lowercase] e. g: {$ content | lower}
Nl2br [Replace line breaks
]
Regex_replace [Regular expression replacement]
Replace [Replace] e. g: {$ content2 | replace: "":"***"}
Spacify [Blank] e. g: {$ content2 | spacify}
String_format [String formatting] e. g: {$ content2 | string_format: "%. 2f "}
Strip [Remove (Extra space)] e. g: {$ content2 | strip}
Strip_tags [Remove htmlTag] e. g: {$ content2 | strip_tags}
Truncate [Intercept] e. g: {$ content2 | truncate: "30 ":"... "}
Upper [Uppercase]
Wordwrap [Line width constraints]
PHP template engine Smarty built-in functions
1. foreachArray Processing
2, IncludeMulti-function usage
3, IFUse of conditional statements
4, Literal stripText processing skills
1.ForeachArray Processing
Similar to our foreach usage in PHP, it is also used to traverse arrays. In practice
Section functions are the same, but foreach is generally used to process one-dimensional arrays in Smarty.
======= Non-key value array {foreach from = $ name item = id} id: {$ id} {/foreach} ====== array with key values {foreach key = j item = v from = $ name} {$ j }: {$ v} {/foreach}
2, IncludeMulti-function usage
{include file="header.htm"}{include file="D:\www\head.htm"}{include file='head.htm' title="MainMenu"}
3, IFUse of conditional statements
{if $name=='ok'}{else}{/if}
4, Literal stripText processing skills
LiteralData is processed as text, and all characters in the template are ignored.
Displays javascript scripts that may contain characters such as braces.
{Literal}