Php code:
<?
Require ("setup. php ");
Define ('pagetitle', 'pagtitle ');
Function insert_top ($ lid, $ sid)
{
Echo "insert function ";
}
$ Smarty = new SmartyRebuild ();
$ Smarty-> assign ('name', 'linux ');
$ Smarty-> assign ');
$ Smarty-> assign ('English _ word', 'My name x4 is linux ');
$ Smarty-> assign ('money', '2017. 123 ');
$ Smarty-> assign ('member', array ('fax' => '010-95888484 ', 'email' => 'linux @ admin.com ',
'Phone' => array ('home' => '000000', 'mobil '=> '000000 ')));
$ TempMember = array ();
$ TempMember ['member'] = 'dsgads ';
$ TempMember ["phone"] ["home"] = "444333 ";
$ Contacts = array ();
$ Contacts [] ["fax"] = "435454 ";
$ Contacts [] ["phone"] = "223523523 ";
$ Contacts [] ["fax"] = "42532532 ";
$ Contacts [] ["phone"] = "7888888 ";
$ Contacts2 = array ('fax' => '000000', 'phone' => '000000'), array ('fax' => '000000 ', 'phone' => '123 '));
$ Contacts3 = array ();
$ Contacts3 [0] = "23523 ";
$ Contacts4 = array ();
$ Contacts4 [0] [0] = "23523 ";
$ Contacts4 [0] [1] = "23523 ";
$ Contacts3 [1] = "23523 ";
$ Contacts4 [1] [0] = "23523 ";
$ Contacts4 [1] [1] = "23523 ";
$ Contacts3 [2] = "23523 ";
$ Contacts4 [2] [0] = "23523 ";
$ Contacts4 [2] [1] = "23523 ";
$ Contacts3 [3] = "23523 ";
$ Contacts4 [3] [0] = "23523 ";
$ Contacts4 [3] [1] = "23523 ";
$ Smarty-> assign ('contacts', $ contacts );
$ Smarty-> assign ('contacts2', $ contacts2 );
$ Smarty-> assign ('contacts3', $ contacts3 );
$ Smarty-> assign ('contacts4', $ contacts4 );
$ Smarty-> assign ('tempmember ', $ tempmember );
$ Smarty-> display ('index. tpl ');
?>
Smarty code:
{Config_load file = 'config. conf '}
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> Smarty learning </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
</HEAD>
<BODY>
{Capture name = banner} {* comment out the content displayed in the middle *}
{Include file = "banner. tpl "}
{/Capture}
{Include file = "banner. tpl" title = "Smarty learning "}
{$ Smarty. get. page} <br/>
{$ Smarty. post. page} <br/>
{$ Smarty. cookies. name} <br/>
{$ Smarty. server. SERVER_NAME} <br/>
{$ Smarty. env. PATH} <br/>
{$ Smarty. session. id} <br/>
{$ Smarty. request. username} <br/>
{$ Smarty. now | date_format: '% Y-% m-% d % H: % M: % s'} <br/>
{$ Smarty. const. PAGETITLE} {* constant *} <br/>
Hello {$ name} {* variable *} <br/>
{Html_select_date display_days = yes} <br/>
{$ Member. fax} <br/>
{$ Member. phone. home} <br/>
{$ Tempmember. member} <br/>
{$ Tempmember. phone. home} {* multi-dimensional array *} <br/>
{# Error_message #}{ * configuration file attributes *} <br/>
{$ Name | lower} {* smarty string function *} <br/>
{$ Name | upper} {* smarty string function *} <br/>
{'Now '| date_format:' % Y-% m-% d'} {* smarty date function *} <br/>
{$ Title | truncate: 11: "..."} {* truncation string extra long plus... *} <br/>
{Mailto | lower address = "mailto: linux@admin.com % 22% 7D % 7B * mailto email *} <br/>
Mailto: % 7B $ tempmember % 7C @ count} {* Total data *} <br/>
{$ English_word | capitalize} {* uppercase letters *} <br/>
{$ English_word | capitalize: true} {* uppercase letters of each word *} <br/>
{$ Title | count_characters: true} {* the length of the string is added with a space of true characters. If it is not set to true, no space is calculated. *} <br/>
{$ Title | cat: 'character after the string'} {* concatenated string *} <br/>
{$ Title | count_words} {* count characters *} <br/>
{$ Title2 | default: "dsgadsgds"}; {* default value output if the variable does not exist *} <br/>
{$ English_word | escape: html} {* convert the HTML in the string to the HTML encoding method *} <br/>
{$ English_word | escape: htmlall} {* convert the HTML in the string to the HTML encoding method *} <br/>
{$ English_word | escape: url} {* convert the HTML in the string to the URL encoding method *} <br/>
{$ English_word | escape: quotes} {* convert the HTML in the string to the HTML encoding method *} <br/>
{$ Title | indent: 100} {* indent specified width *} <br/>
{$ Title | regex_replace: "/Yes/": ""} {* Replacement character of Regular Expression *} <br/>
{$ Title | replace: "to": ""} {* Replace replacement character *} <br/>
{$ English_word | spacify: "|"} {* Separator string *} <br/>
{$ Money | string_format: "%. 2f"} {* Number of Float formatted digits *} <br/>
{$ Money | string_format: "% d"} {* The number of formatted numbers is INT *} <br/>
{$ English_word | strip: "& nbsp;"} {* replace space *} <br/>
{$ English_word | strip_tags: false} {* replace tag *} <br/>
{$ English_word | truncate: 10: "..."} {* truncates a specified length of characters. The default length is 80 characters. *} <br/>
{$ English_word | wordwrap: 10} {* length of the string to wrap. The default line feed length is 80 *} <br/>
{$ English_word | upper | spacify | truncate: 30 :"... "} {* Smarty supports the combination of multiple functions. This combination is a string that is separated by uppercase and then truncated with a specified length *} <br/>
{Foreach name = outer item = contact from = $ contacts} {* foreach loop array *}
{Foreach key = key item = item from = $ contact}
{$ Key }:{ $ item} <br/>
{/Foreach}
{/Foreach}
{Foreach name = outer item = contact2 from = $ contacts2}
{Foreach key = key item = item from = $ contact2}
{$ Key }:{ $ item} <br/>
{/Foreach}
{/Foreach}
{Include_php file = "function. php"} {* contains the specified php file *}
{Insert name = "top" lid = "toplid" sid = "topsid"} {* call the insert_top PHP function. The function parameter is the value of lid and sid *}
{If 1 eq 1} {* condition judgment statement *}
1 = 1
{Elseif 1 ne 1}
1! = 1
{Elseif 1 gt 1}
1> 1
{Elseif 1 lt 1}
1 <1
{Elseif 1 gte 1}
1> = 1
{Elseif 1 lte 1}
1 <= 1
{Elseif not 1 eq 1}
Not 1 = 1
{Elseif (1 mod 1) eq 1}
<Font color = "red"> 1% 1 = 1 </font>
{Else}
Your product is really bad.
{/If}
{Ldelim} function insert_top {rdelim} is insert_top {* output brackets *}
{Literal} {* Add HTML, script code, etc *}
<Script language = "javascript" type = "text/css">
<! --
Function load ()
{
Alert ('page loading ....');
}
// -->
</Script>
{/Literal}
{* Contains a PHP statement *}
{Php}
Echo "php code running ";
{/Php}
{Section name = member loop = $ contacts3 show = true} {* while loop show whether to SHOW loop content in section *}
{If $ smarty. section. member. first}
First
{/If}
{If $ smarty. section. member. last}
Last
{/If}
Current loop rownum: {$ smarty. section. member. rownum} <br/>
Current loop iteration: {$ smarty. section. member. iteration} <br/>
Index: {$ smarty. section. member. index} index_prev: {$ contacts3 [member. index_prev]} index_next: {$ contacts3 [member. index_next]} index: {$ contacts3 [member. index]} member: {$ contacts3 [member]}
{Section name = memberchild loop = $ contacts4 [member] max = 2}
Memberchild: {$ contacts4 [member] [memberchild]}
{/Section}
Total: {$ smarty. section. member. total} {* Data Length or total number of records *}
{/Section}
</BODY>
</HTML>