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