Templates engine--smarty under
Directory
Template engine --smarty Next 1
one, built-in function 2
1 , If...elseif...else...if 2
2 , Ldelim , Rdelim 2
3 , literal 3
4 , PHP 3
5 , Section 4
6 , Strip 6
Second, the Custom function ( Plugins ) 7
1 , Counter 7
2 , Cycle 8
3 , Debug 8
4 , Fetch 9
5 , Html_image 10
6 , html_table 10
7 , html_checkboxes check box 10
8 , html_options 11
9 , Html_radios 11
Iii. Comprehensive Cases --php+smarty complete the data paging 12
1 , database design 12
2 , Design HTML Interface ( OK ) 12
3 , writing a program 12
Iv. procedure Chapter 13
1 , constant 13
2 , variable 13
3 , common methods 14
five, Cache chapter 17
1 , Smarty the cache in 17
2 , using Smarty Cache 17
3 , Cache action 17
4 , cache files from " What " and come? 18
5 , Smarty working principle Diagram 18
6 , iscached Method 18
7 , clear Cache 19
8 , single-page multi-cache 19
9 , Cache collection 20
Ten , local cache 20
Six, filter 22
1 , what is a filter 22
2 , verifying the existence of filters 22
Vii. Integration Smarty to the MVC one , built-in functions 1,if...elseif...else...if
Basic syntax
{if}
{ElseIf}
{Else}
{/if}
Function: Implement if selection structure
Example code:
Run Result: Write code 2, Ldelim, Rdelim
{Ldelim}
{Rdelim}
Function: Output Smarty label left and right delimiter
Example code:
Operating effect:
3, literal
Basic syntax:
{literal}
Content (CSS code or JS code)
{/literal}
Function: The data in the literal label area will be treated as text, at which point the template ignores all character information inside it. This feature is used to display CSS or JavaScript scripts that may contain character information, such as curly braces. When this information is in the {literal}{/literal} tab, the template engine will not parse them and display them directly.
Example code:
The effect is as follows:
4. PHP
Basic syntax
{PHP}
PHP code
{/php}
Features: allows us to use PHP code in the Smarty template engine (but not recommended)
In Smarty3.0 the syntax has been abolished, if you want to use it, please use the SMARTYBC portal
Example:
Effect: 2015-02-11 00:00:00 5, section
Basic syntax:
{Section name= name loop= Loop Array (number of times) start= start (0) step= Step (1) max= maximum number of cycles}
{Sectionelse}
{/section}
Function: Implement an array (index starting at 0 and continuous) traversal
Parameter description:
Loop: the array to traverse
Name: The traversal index is placed in name each time it is traversed
Start: Index to start by default
Step: Steps or Pace, default is 1
Max: Maximum number of cycles
Example code:
Example 1: Traversing a one-dimensional array
Operation Result:
Section vs. foreach:
foreach can traverse an array, and after each traversal, the traversed content is saved in the item option, which is a true traversal of the arrays. Similar to the Foreach Loop in PHP
The section can also implement an array traversal, but each time the loop is used, the system simply determines the number of elements in the array and determines the number of loops, and puts the circular index into the name option, which is not a true traversal of the array, but is similar to a for loop in PHP code.
Example 2:section parameter use
The effect is as follows:
Example 3:section traversing a two-dimensional array
Operation Result:
Section attached properties
{$smarty. Section.name.index}: Circular index, default starting from 0
{$smarty. Section.name.index_prev}: Last index of the current index
{$smarty. Section.name.index_next}: Next index for the current index
{$smarty. section.name.iteration}: First loop (iteration)
{$smarty. Section.name.first}: The condition is true when the first loop
{$smarty. Section.name.last}: The condition is true when the last loop
{$smarty. section.name.total}: Total number of loops
Example code:
Operating effect:
6, Strip
{Strip}
Formatting code
{/strip}
Function: Remove the leading and trailing spaces and line breaks of elements
Example code:
Operating effect:
right mouse button to view source code:
two , custom Functions (plugins) 1,counter
Basic syntax
{Counter start=0 skip=2 Print=false}
Function: Counter
Parameter description:
Start: Default start number, default is 1
Skip: Step or pace
Print: Whether the output is currently
Sample code
Operating effect:
2. Cycle
Function: Realize wheel display operation
Basic syntax:
<tr bgcolor= "{cycle values=" #eeeeee, #d0d0d0 "}" >
Example code:
Operating effect:
3. Debug
Function: Implement the debugging of the source code
Basic syntax: {DEBUG}
Example code:
{Debug}
Operating effect:
4. Fetch
Basic syntax:
{Fetch file= "load file path" assign= "variable"}
Reference:
{$ variable}
Example code:
Operating effect:
5, Html_image
Basic syntax
{html_image file= "pumpkin.jpg"}
Example code:
6 , Html_table
Basic syntax:
{html_table loop= $data cols=4 table_attr= ' border= "0"}
Function: Convert the array (simple) into a table
Parameter description:
Loop: the array to traverse
COLS: How many columns are displayed
Table_attr: Table Properties, multiple properties are separated by spaces, or you can use style
Example code:
Operating effect:
7 , html_checkboxes check box
Basic syntax:
{html_checkboxes name= ' cust ' values= $cust _ids checked= $customer _id output= $cust _names separator= "<br/>"}
Parameter description
Name: check box names (primarily for receiving)
Values: Value (array) of a checked Value property
Checked: Selected value (Array)
Output: Displayed value (array)
Sepatator: The delimiter of elements and elements
Example code:
Operating effect:
8, Html_options
Basic syntax:
<select name=customer_id>
{html_options values= $cust _ids selected= $customer _id output= $cust _names}
</select>
Parameter description:
Value of the Value:option option (array)
Selected: Selected option (array)
Output: Displayed value (array)
Example code:
Operating effect:
9, Html_radios
Basic syntax:
{Html_radios values= $cust _ids checked= $customer _id output= $cust _names separator= "<br/>"}
Parameter description:
Value of the Values:radio option
Checked: Default selected value (required to be a fixed value)
Output: Text information to be exported (array)
Separator: The delimiter between elements and elements
Example code:
Operating effect:
20150211--smarty2-01