PHPLIB Template System Introduction

xiaoxiao2021-03-06  60

This article tells some basic grammar and functions in phplib

Boeiblog is a single-user version of the single-user version of the network log program that supports multi-template

Its template engine is PHPLIB7.4. This release has been fixed most of the BUG, ​​the file is located in class / template.class.php, interested friends can open. This is a parsed template, not a compilation type such as Smarty. The advantage of using this template is that the template page can be very simple, but the program is slower because of the label in the template. Good in this system is prepared for personal users. The efficiency is placed in the second place, and the ease of use is to be in the first, so it is still a template for phplib.

Syntax introduction: The common methods in phplib are set_file, set_block, set_var, parse, ppaasre, p, get, etc.

Disclaimer: Since the system is PHPLIB, if there is a large bracket pair in the page, this will replace it with a blank, so when writing this article, use "[[[[[", "]] to replace the braces. Everyone is using braces when using braces, here is only for this convention for writing articles.

Set_file: Yes used to introduce template files. usage:

CODE:

$ T-> set_file ("Show_main", "main.htm"); or $ t-> set_file ("show_header" => "header.htm", "Show_main" => "main.htm"));

SET_BLOCK: Used to declare a block

usage:

$ T-> set_block ("show_main", "rowlist", "rl");

Slightly explanation, show_main is the file handle acquired with set_file, and Rowlist is the area identifier in the template page is generally written.

CODE:

[[param]]

As mentioned above, "Tr> is used as a block so that you can generate multi-line lists with cycles.

Blocks can be nested

CODE:

[[param]] < ! - End rowlist ->

As shown above, this states a nested block, which uses this way in the BoEiblog's album, interested friends can find it.

For nested templates, we can use this way

$ T-> set_block ("show_main", "rowlist", "rl"); // The parameter inside is included in the front, the last one is an alias, mainly used to block identification

$ T-> Set_block ("Rowlist", "Collist", "CL"); // The first parameter is the name of the outer block, the second is his own music, the third is an alias

Special attention when recurring such a block

as follows:

CODE:

$ T-> Set_block ("Show_main", "RowList", "RL"); $ T-> Set_block ("Rowlist", "Collist", "Cl"); for ($ I = 0; $ I <5; $ I ) {$ T-> Set ("cl"); / / This is to perform a cleaning on the additional column loop, otherwise it will be a pile of things for ($ II = 0; $ II <5; $ II ) {$ T-> set_var ("param", "boeiblog"); $ t-> parse ("cl", "collist", true); // True parameter indicates that this is append} $ t-> parse ("rl "," Rowlist ", true); // The TRUE here is also a table append} The above code will generate a 5x5 table, and a BOEIBLOG will appear in each cell.

SET_VAR: The $ t-> set_var ("param", "Boeiblog") used to be used to replace the above code; it is to replace the param variable in the template to Boeiblog this string, of course, can be replaced with variables, such as:

CODE:

$ CURDATE = DATE ("Y-M-D"); $ T-> Set_var ("Param", $ CURDATE);

Set_var also has additional properties, such as:

CODE:

$ CURDATE = DATE ("Y-M-D"); for ($ I = 0; $ I <10; $ I ) {$ T-> set_var ("param", "
". $ curdate, true);}

This will result in ten consecutive current dates

Sometimes you can use set_var's additional properties to replace Block's loop.

Set_var is an array, such as:

CODE:

$ t-> set_var (array ("param" => "boeiblog", "title" => "USA");

The template is as follows:

CODE:

[[param]], [[Title]]

PARSE: Used to resolve file When we handle all variables in the template, you can parse this template with Parse. This is the last few steps for template processing. Such as:

CODE:

$ T-> set_file ("show_index", "index.htm"); $ t-> set_file ("show_main", "main.htm"); $ t-> set_var ("param", "boeiblog"); $ T-> Parse ("main", "show_main");

The templates we use may be:

CODE:

Main.htm

[[param]]

If there is another template at this time, its structure is as follows:

CODE:

Index.htm

[[Main]]

The above code will replace the variables in main.htm to BoEiblog and place it to the Main in Index.htm, and finally form an output page after forming a table resolution in the

tag.

P: Used to output the page such as:

CODE:

$ T-> set_file ("show_index", "index.htm"); $ t-> set_file ("show_main", "main.htm"); $ t-> set_var ("param", "boeiblog"); $ T-> PARSE ("main", "show_main"); $ T-> Parse ("index", "show_index"); $ t-> p ("index"); // will overdex page Output, pay attention to main.htm has been embedded in Index.htm, so do not have to be $ t-> p ("main");

PPARSE: Like P is also used to output the page such as:

CODE:

The above code can simplify $ t-> set_file ("show_index", "index.htm"); $ t-> set_file ("Show_main", "main.htm"); $ t-> set_var ("param", " "Boeiblog"); $ T-> Parse ("main", "show_main"); $ T-> PPARSE ("INDEX", "Show_index"); // Incoming P and Parse together, complete the resolution immediately and Output

GET: Used to get the file content such as:

CODE:

$ T-> set_file ("show_index", "index.htm"); $ t-> set_file ("show_main", "main.htm"); $ t-> set_var ("param", "boeiblog"); $ T-> Parse ("main", "show_main"); $ t-> parse ("index", "show_index"); $ getStr = $ t-> get ("index"); echo $ getstr; // you This will actually be the same as P. With GET, we can easily obtain the contents of the generated page, which can be used for the generation of static pages. It is very convenient to see phplib to handle static pages.

转载请注明原文地址:https://www.9cbs.com/read-90856.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.032, SQL: 9