Home > Backend Development > PHP Tutorial > Key codes for generating static pages with smarty template engine

Key codes for generating static pages with smarty template engine

WBOY
Release: 2016-07-25 08:58:21
Original
875 people have browsed it
This article introduces the key code for generating static pages in the smarty template engine. Friends in need can refer to it.

In smarty, there is a method fetch() to get the content of the template page. Its declaration prototype is:

<?php  
    function fetch(  
      $resource_name,  
      $cache_id=null,  
      $compile_id=null,  
      $display=false)  
?>
Copy after login

Code description: The first parameter is the template name, the second parameter is the cached id, the third parameter is the compilation id, and the fourth parameter is whether to display the template content.

To generate a static page, you need to use this method.

<?php  
   $smarty= newSmarty(); 
    //其它模板替换语法…  

    //取得页面中所有内容, 注意最后一个参数为false  
   $content=$smarty->fetch(’模板名称.tpl’, null, null, false);  

    //将内容写入至一个静态文件 
    $fp=fopen(’news.html’,'w’);  
   fwrite($fp,$content); 
    fclose($fp); 
//by bbs.it-home.org
?>
Copy after login

In this way, the static page news.html is generated.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template