The biggest function of Smarty is to cache pages of templates. That is, two steps can be completed through Smarty: Compilation + parsing.
Step 1: compile. It refers to replacing the tag of the template file with pure php, and then saving the cache location. The saved file extension is PHP. I call this step compilation (this is my own name, not official)
Step 2: parse. That is, the PHP file just compiled is parsed and executed ~~ This does not need to be explained.
Add the following code to the Smarty. class. php file.
Function MakeHtmlFile ($ file_name, $ content)
{// Create if the directory does not exist
If (! File_exists (dirname ($ file_name ))){
If (! @ Mkdir (dirname ($ file_name), 0777 )){
Die ($ file_name. "Directory creation failed! ");
}
}
If (! $ Fp = fopen ($ file_name, "w ")){
Echo "file opening failed! ";
Return false;
}
If (! Fwrite ($ fp, $ content )){
Echo "file writing failed! ";
Fclose ($ fp );
Return false;
}
Fclose ($ fp );
Chmod ($ file_name, 0666 );
}
This function is used to save files ~~
The call method is as follows:
Require '../libs/Smarty. class. php ';
$ Smarty = new Smarty;
// & Hellip; Omitting variable definition and assignment
// $ Smarty-> display ('index. tpl ');
$ Content = $ smarty-> fetch ("index. tpl ");
$ Smarty-> MakeHtmlFile ('./index.html', $ content); // generate
From the PainsOnline Column