SmartTemplate study notes

xiaoxiao2021-03-06  69

table of Contents

1, smartTemplate efficiency

2, basic variable

3, logic computing structure

4, mode (Methods)

5, expansion (extensions)

-------------------------------------------------- ----------------------

1, smartTemplate efficiency

Although he has a lot of procedures to form a powerful function, only when you are executed, there is no need to worry about the speed of this, the same set of template systems is optimized for the fastest implementation efficiency. Compared to the common Smarty currently in the market, there is a lot of fast (Smarty uses a later cache, so it may not be very accurate).

2, smartTemplate variable

Array's variable is assigned by SmartTemplate built-in function assign () to assign

The specific syntax is as follows

Assign (variables in the template, content to be replaced)

or

Assign (array content)

As in other programs variables, the variable of SmartTemplate is included in special {}. The content inside can be String, Array, Int, or Long Text, etc. (Basic PHP support)

When stores Array data, SmartTemplate uses our common parent-class split ".", So a special Array data consists of Array Handle and the specific location index (Numerical Index or Associative Index).

Below is an example

Run the following procedure in the PHP environment

Code:

$ Template = New SmartTemplate ('Template.html');

$ text = 'Sample text';

$ Template-> Assign ('Title', $ TEXT);

$ Template-> Output ();

?>

stencil

Code:

{title}

Output

Code:

Sample Text

In the case of only one array, you can directly omit the Array Handle, just when using JavaScript, Document.Window.close () can be omitted for Window.Close ()

PHP

Code:

$ User = array (

'Name' => 'john doe',

'Group' => 'admin',

'Agn' => '42',

);

$ Template = New SmartTemplate ('user.html');

$ Template-> Assign ($ user);

$ Template-> Output ();

?>

stencil

Code:

Name: {name}

Group: {group}

Age: {age}

Output

Code:

Name: John Doe

Group: admin

Age: 42

Here is another example. Use SmartTemplate's loop function xxxxxx

His function is similar to foreach (), as long as there is something, it will be circulated

Code:

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:

Sample Links

{title}

Code:

Sample Links

PHP

apache

mysql

3, smartTemplate logic control structure

★ IF and end if

grammar:

variable has been assigned!

If the change is directly kept directly, the variable will return 0 when the variable is null, otherwise it returns 1

your name is john doe!

== Determine whether it is equal, if equally returned 1, no phase, etc.

Your name is not john doe!

! = Judgment is not equal, if it is established to return 1, then return 0

example:

PHP

Code:

Require_once "class.smartTemplate.php";

$ Page = New SmartTemplate ("if.html");

$ Page-> Assign ('Username', 'John Doe');

$ Page-> Assign ('usergroup', 'admin ";

$ Page-> Assign ('Picture', '');

$ Page-> Output ();

?> HTML

Code:

Welcome, {username}

admin Login

Output code:

Welcome, John Doe

admin Login

★ IF's child ELSE

If the ELSE clause appears in a logical loop, it will be run when the conditions of the IF are not true.

example

Code:

Require_once "class.smartTemplate.php";

$ Page = New SmartTemplate ("else.html");

$ Page-> Assign ('Username', 'John Doe');

$ Page-> Assign ('usergroup', 'admin ";

$ Page-> Assign ('Picture', '');

$ Page-> Output ();

?>

stencil

Code:

Welcome, {UserName}

Picture Not Available!

admin Login

You are in Guest MODE!

Output

Code:

Welcome, John Doe

Picture Not Available!

admin Login

★ Elseif

Elseif is a structure in Else and IF combination, meaning "if ..."

The following is an example

Code:

Require_once "class.smartTemplate.php";

$ Page = New SmartTemplate ("elseif.html");

$ Page-> Assign ('UserGroup', 'Internal');

$ Page-> Output ();

?> Template file

Code:

administrator login

Help staff login

normal way to log in

You don't Even Have a Usergroup!

Output obtained by running PHP

Code:

normal 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) and in and will be read and repeatedly executed.

Additional:, each Associative Array (matrix for string) will have two additional values

Rowcnt: This element is in the specific position of the parent matrix (0, 1, 2, 3, ... n) (it is currently in the first matrix)

Rowbit: The last bit of the matrix serial number. (0, 1, 0, 1, 0, 1, ...)

Below is an example

PHP code:

Code:

Require_once "class.smartTemplate.php";

$ Page = New SmartTemplate ("Begin_END.html");

$ users = array

Array ('Name' => 'John Doe', 'Group' => 'Admin'),

Array ('Name' => Jack Doe ',' Group '=>' Support '),

Array ('name' => 'james doe', 'group' => 'guest'),

Array ('name' => 'Jane Doe', 'Group' => 'Guest'),

);

$ Page-> Assign ('Users', $ User);

$ Page-> Output ();

?>

HTML template

Code: