Home  >  Article  >  Backend Development  >  Use libtemplate to generate static web pages_PHP tutorial

Use libtemplate to generate static web pages_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:07:25750browse

by coldwind/iwind/month/ccterran http://iwind.org
For a long time, I asked others how to implement static web pages, and also asked questions to Nagging. Now, I finally came up with a very good idea. The simple way is to use libtemplate to implement it.
Everyone, take a look: http://doc.iwind.org
Now let me talk about how to implement static web page output.
1. Modify libtemplate.
Add two functions
//Save the analysis results to a file
function savetofile ($dir,$varname){
$data=$this- >finish($this->get_var($varname));
$fp=fopen($dir,"w+");
fwrite($fp,$data);
}
The dir in the function is where we want to save the file. varname is $target in libtemplate, used as follows:
$tpl->set_file("main","main.tpl");
...
$tpl->parse("mains ","main");
$tpl->savetofile("html/main.html","mains");
I believe readers who understand libtemplate can easily understand these.
//Cleared Assignment array
function renew(){
$this->varkeys=array();
$this->varvals=array();
$this->file=array( ; ;set_file("main","main.tpl");
...
$tpl->parse("mains","main");
$tpl->savetofile(" html/main.html","mains");

But once we change the template for article display, how can we quickly update the previously generated static web page? Obviously we need to loop the output. The example is as follows:
html_info(){//Single file, just a similar example
global $tpl;
$tpl->set_file("main","main.tpl");
...
$tpl->parse("mains","main");
$tpl->savetofile("html/main.html","mains");
$tpl->renew (); // Crucial
}
//Loop output
for($i=0;$i<$total;$i++){
                                                                                                          
}
So it is very simple to generate static pages. Updating is not as complicated as imagined.
(End)



http://www.bkjia.com/PHPjc/315097.html

www.bkjia.com

true

TechArticleby coldwind/iwind/month/ccterran http://iwind.org For a long time I asked people everywhere How to implement a static web page, I asked Nagging a question, and now, I finally came up with a very simple one...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn