Home  >  Article  >  Backend Development  >  thinkphp 使每个模板页都包含一个header文件跟一个footer文件

thinkphp 使每个模板页都包含一个header文件跟一个footer文件

WBOY
WBOYOriginal
2016-06-13 12:00:591474browse
MyException - 代码迷
首页
  • Web开发
  • Android
  • J2EE
  • PHP
  • Linux/Unix
  • MySql
  • C#
  • 更多...
当前位置: 代码迷 » PHP » thinkphp 使每个模板页都包含一个header文件跟一个f

thinkphp 使每个模板页都包含一个header文件跟一个footer文件

www.MyException.Cn,网友分享于:2014-06-30   浏览:6次
thinkphp 使每个模板页都包含一个header文件和一个footer文件

在开发的过程中,经常遇到要使每个模板页都包含一个header文件和一个footer文件,thinkPHP的模板布局为我们提供了一个叫全局配置方式能够解决这个问题。

1. 在配置文件中开启LAYOUT_ON 参数(默认不开启),并且设置布局入口文件名LAYOUT_NAME(默认为layout)

    'LAYOUT_ON'=>true,    'LAYOUT_NAME'=>'layout',

2. 在模板目录下建立一个layout.html文件,文件内代码如下:

    <include file="Public:header"></include>    {__CONTENT__}    <include file="Public:footer"></include>

{__CONTENT__} 为特定字替换符串,如果模板为User/add.html,thinkPHP先读取layout模板之后,会再解析User/add.html 模板文件,并把解析后的内容替换到layout布局模板文件的{__CONTENT__} 特定字符串。

3.

    'TMPL_LAYOUT_ITEM'      =>  '{__REPLACE__}' //通过设置来改变这个特定的替换字符串

    'LAYOUT_NAME'=>'Layout/layoutname', //指定其他位置的布局模板

更加详细的介绍:http://www.thinkphp.cn/info/183.html


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