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

Key codes for generating static pages with smarty template engine

WBOY
WBOYOriginal
2016-07-25 08:58:21837browse
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)  
?>

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
?>

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



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