Common Methods in phplib include set_file, set_block, set_var, parse, ppasre, p, and get.
Common Methods in phplib include set_file, set_block, set_var, parse, ppasre, p, and get.
Syntax introduction:
Common Methods in phplib include set_file, set_block, set_var, parse, ppasre, p, and get.
Statement: because the system uses phplib, if there is a braces on the page, this will be replaced with a blank space, so when writing this article, use "[[", "]" to replace braces. When we use it, we use braces to make it easier to write articles.
Set_file: used to introduce the template file.
Usage:
The Code is as follows:
$ T-> set_file ("show_main", "main.htm ");
Or
$ T-> set_file (array (
"Show_header" => "header.htm ",
"Show_main" => "main.htm"
));
Set_block: Used to declare a block
Usage:
$ T-> set_block ("show_main", "rowlist", "RL ");
Show_main is the file handle obtained using set_file, and rowlist is the region ID on the template page.
The Code is as follows:
As shown aboveAs a block, you can use a loop to generate a list of multiple rows.
Blocks can be nested.
The Code is as follows:
As shown above, this declares a nested block, which is used in the image volume of boeiBlog. If you are interested, you can find it.
For nested templates, we can use
$ T-> set_block ("show_main", "rowlist", "RL"); // the parameters in the table are contained from the beginning to the end, and the last one is an alias, mainly used for block Recognition
$ T-> set_block ("rowlist", "collist", "CL"); // The first parameter is the name of the external block, and the second parameter is your own name, the third is the alias.
Pay special attention to loop through such blocks.
As follows:
The Code is as follows:
$ T-> set_block ("show_main", "rowlist", "RL ");
$ T-> set_block ("rowlist", "collist", "CL ");
For ($ I = 0; $ I <5; $ I ++)
{
$ T-> set ("CL"); // here we need to clear the appended column loop once, otherwise there will be a bunch of more things
For ($ ii = 0; $ ii <5; $ ii ++)
{
$ T-> set_var ("param", "boeiBlog ");
$ T-> parse ("CL", "collist", true); // The true parameter indicates that this is an append.
}
$ T-> parse ("RL", "rowlist", true); // true here is also table appending.
}
The code above will generate a 5x5 table, and a boeiBlog will appear in each cell.
Set_var: Used to replace variables
In the above Code, $ t-> set_var ("param", "boeiBlog") is to replace the param variable in the template with the boeiBlog string. Of course, you can also replace it with a variable, such:
The Code is as follows:
$ Curdate = date ("Y-m-d ");
$ T-> set_var ("param", $ curdate );
Set_var also has append attributes, such:
The Code is as follows:
$ Curdate = date ("Y-m-d ");
For ($ I = 0; $ I <10; $ I ++)
{
$ T-> set_var ("param ","
". $ Curdate, true );
}
This will generate ten consecutive current dates
Sometimes the append attribute of set_var can be used to replace the block loop.
Set_var can use arrays, such:
The Code is as follows:
$ T-> set_var (array (
"Param" => "boeiBlog ",
"Title" => "Bai AI network"
));
The template is as follows:
The Code is as follows:
Parse: Used to parse Files
After processing all the variables in the template, you can use parse to parse the template. This is the last process of template processing.
For example:
The Code is as follows:
$ 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 template we use may be:
The Code is as follows:
Main.htm
If there is another template, its structure is as follows:
Index.htm
[[Main]
In this case, the code will replace the variables in main.htmwith boeiblogand then put them to the main in index.htm. Finally,
Table in tag
After the resolution is complete, the output page is displayed,
P: Used to output pages
For example:
The Code is as follows:
$ 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"); // The entire indexpage is output, and main.htmis inserted into index.htm, so $ t-> p ("main") is not required ");
Pparse: Same as p, it is also used to output pages.
For example:
The Code is as follows:
The above code can be simplified as follows:
$ 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"); // combine p and parse to complete parsing and output immediately.
Get: get File Content
For example:
The Code is as follows:
$ 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 will see that this is actually the same as p.
With get, we can easily obtain the content of the generated page, which can be used for static page generation. We can see that phplib is very convenient for processing static pages.