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: Php $ template = new smartTemplate ('template.html'); $ text = 'sample text'; $ TEMPLATE-> Assign ('Title', $ Text) $ Template-> Output ();?> Temple code: {title} html> Output code: Sample text html> 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: php $ user = array ('name' => '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 $ links = array (Array ('Title' => '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:
! - Endif Name ->! = Judgment is not equal, if it returns 1, it returns 0 examples: PHP code: Php require_once "class.smartTemplate.php"; $ Page = new smartTemplate ("if.) HTML "); $ Page-> Assign ('UserName', 'John Doe'); $ Page-> Assign ('UserGroup'); $ Page-> Assign ('Picture', '); $ Page-> Output ();?> HTML code:
Example code: Php require_once "class.smarttemplate.php"; $ page-> assign ('username', 'John Doe'); $ Page-> Assign 'UserGroup', 'admin'); $ Page-> Assign ('Picture', ''); $ Page-> Output ();?> Template Code:
★ 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: Php require_once "class.smartTemplate.php"; $ Page = New SmartTemplate ("Begin_END.html"); $ Users = array (array ", 'group' => '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: