SmartTemplate study notes

xiaoxiao2021-03-06  36

SmartTemplate learning notes [zt] ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------- Catalog 1, SmartTemplate Efficiency 2, Basic Variable 3, Logic Operation Structure 4, Methods 5, expansions (Extensions) is not completed --------------------------------------- ------------------------------- 1, smartTemplate efficiency Although he has a lot of procedures to form a powerful function, Only when you are executed, you don't have to worry about the speed of this, the same set of template systems is optimized for the fastest implementation efficiency, compared to the current market common Smarty, there is a lot ( Smarty uses a later cache, so it may not be very accurate). 2, SmartTemplate variables Array variable is the specific syntax assigned by SmartTemplate built-in function assign () as followsign (variable in the template, the content to be replaced) or Assign (Array content) is just like other programs, SmartTemplate Variables are included by special {}. The content inside can be string, array, int, or long text, etc. (Basic PHP support) When saving Array data, SmartTemplate uses our common parent-level division ".", So a special array data Composed of Array Handle and the specific location (Numeric Index or Associative INDEX).

Below is an example of running the following program code in a PHP environment: Assign ('Title', $ Text) $ Template-> Output ();?> Temple code: {title} Output code: Sample text In the case of only one array, you can omit the array directly Handle, just when using JavaScript, Document.Window.close () can omit the window.close () PHP code: 'john doe', 'group' => 'Admin', 'agn' => '42',); $ template = new smarttemplate ('user.html'); $ TEMPLATE-> Assign ($ us); $ template-> output ();?> Template code : Name: {name} group: {group} age: {agn} Output code: Name: John Doe Group: Admin Age: 42 is another example.

Use SmartTemplate's loop function xxxxxx His function like foreach (), as long as there is something, you have been loop display code: 'PHP', 'URL' => 'http://www.php.net/', array ('title' => 'apache', 'url' => 'http : //www.php.net/ ',), array (' title '=>' MySQL ',' url '=>' http://www.mysql.com/ ',); $ TEMPLATE = NEW SmartTemplate ('Links.html'); $ Template-> Assign ('Links', $ Links); $ TEMPLATE-> OUTPUT ();?> HTML template code:

Sample Links < ! - Begin Links -> php apache Mysql 3, SmartTemplate logic control structure ★ if and end if syntax: variable has been assigned! If the IF is directly with the variable, the variable will return 0 when the variable is null, otherwise returns 1! - if Name == "john doe" -> your name is john doe! == Determine if it is equal, if equally return 1, not equal return 0 Your name is not john doe! <

! - Endif Name ->! = Judgment is not equal, if it returns 1, it returns 0 examples: PHP code: Assign ('UserName', 'John Doe'); $ Page-> Assign ('UserGroup'); $ Page-> Assign ('Picture', '); $ Page-> Output ();?> HTML code:

Welcome, {username} admin Login
Output code:

Welcome, John doe admin Login
★ If The ELSE clause appears in a logical cycle, and it will be run when the conditions of the IF are not true.

Example code: assign ('username', 'John Doe'); $ Page-> Assign 'UserGroup', 'admin'); $ Page-> Assign ('Picture', ''); $ Page-> Output ();?> Template Code:

Welcome, {username} <-! ENDIF -> <-! IF picture -> <-! ELSE ->! Picture not available
< ! - Endif Picture -> admin Login
you are In Guest Mode! Output code:

Welcome, John Doe Picture Not Available!
Admin Login
★ Elseif elseif is a structure in which Else and IF combines, its meaning is "if ..." is an example code: Assign ('UserGroup', 'INTERNAL'); $ Page-> Output ();?> Template file code: administrator login Help staff login Ordinary way to log in
you don't even has usergroup! Run the output code obtained by PHP: Ordinary Way to log in

★ Begin ... End This statement is used to read a value of an integer index matrix (Numeric Array, an array of numbers). The sub-matrix of each integer matrix becomes a matrix indexed in a string (Associative Array) ) The statement between and will be read and repeated. Additional:, each Associative Array (matrix of string) will have Two additional values ​​rowcnt: This element is in the specific position (0, 1, 2, 3, ... n) in the parent matrix (is currently in the first matrix) ROWbit: matrix serial number. (0 , 1, 0, 1, 0, 1, ...) The following is an example PHP code: code: 'admin'), array ('name' => 'jack doe",' group '=>' support ', array (ARRAY) 'Name' => 'james doe', 'group' => 'guest'), array ('name' => 'jane doe', 'group' => 'guest'),); $ Page-> Assign 'users', $ users); $ page-> output ();?> HTML template code: