by Coldwind/iwind/month/ccterran http://iwind.org
For a long time I have been asking people how to implement static Web pages, but also to nagging questions, and now, I finally came up with a very simple way, that is to use libtemplate to achieve it.
See all: http://doc.iwind.org
Let's talk about how to implement static Web page output.
1, modify the libtemplate.
Add two functions
Save the results of the analysis 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 the libtemplate in $target, using the following:
$TPL->set_file ("main", "Main.tpl");
...
$tpl->parse ("mains", "main");
$tpl->savetofile ("html/main.html", "mains");
It is easy for readers who understand Libtemplate to understand this.
Clears an array of values that have been assigned
function Renew () {
$this->varkeys=array ();
$this->varvals=array ();
$this->file=array ();
}
This clears the impact of the previous template analysis.
2, implement static output.
If the output is a single file as in the above example.
$TPL->set_file ("main", "Main.tpl");
...
$tpl->parse ("mains", "main");
$tpl->savetofile ("html/main.html", "mains");
But once we have changed the template shown in the article, how can we make the previously generated static Web page update quickly? It is clear that you want to loop the output. Examples are 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 ();//Critical
}
Loop output
for ($i =0; $i < $total; $i + +) {
...
Html_info;
}
So it's very simple to implement a static page. The update is not as complicated as it might seem.
Finish
http://www.bkjia.com/PHPjc/315097.html www.bkjia.com true http://www.bkjia.com/PHPjc/315097.html techarticle by Coldwind/iwind/month/ccterran http://iwind.org for a long time I have been asking people how to implement static Web pages, but also to nagging questions, and now, I finally came up with a very simple ...