thinkphp,一、模板文件layou.html的使用设置详细说明和多种...
<p class="MsoNormal" align="left"><b><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">(一)在<span lang="EN-US">html</span>文件中引用模板:</span></b><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">首先需要定义一个布局模板文件,放到<span lang="EN-US">
application/index/view/layout.html </span>内容如下:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{include
file="user/header" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{__CONTENT__}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{include
file="user/footer" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">application/index/view/user/index.html
</span><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:
MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">改成:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{layout
name="layout" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">在<span lang="EN-US">index</span>模板文件中开头定义<span lang="EN-US">layout </span>标签 ,表示当前模板使用了布局,布局模板文件为<span lang="EN-US">layout.html </span>,<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">布局模板中的<span lang="EN-US"> {__CONTENT__} </span>会自动替换为解析后的<span lang="EN-US">index.html</span>内容。<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">如果你的布局模板中不是使用<span lang="EN-US">{__CONTENT__} </span>的话,可以改成:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{layout
name="layout/newlayout" replace="" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">那么回自动读取模板文件<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">application/index/view/layout/newlayout.html
</span><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:
MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">,内容如下:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{include
file="user/header" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt"><o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">{include
file="user/footer" /}<o:p></o:p></span></p><p class="MsoNormal" align="left"><b><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">(二)在<span lang="EN-US">CONFIG</span>文件中设置统一模板。</span></b><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">如果你所有的模板文件都统一使用布局,并且都是有同一个布局模板,那么可以统一配置而不需要在模板文件中使用<span lang="EN-US">layout </span>标签定义。<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">在应用配置或者模块配置中添加如下设置参数:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">'template'
=> [<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">'layout_on'
=> true,<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">'layout_name'
=> 'layout',<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">'layout_item'
=> '']<o:p></o:p></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">可以使用该方法临时关闭布局,<span lang="EN-US">$this->view->engine->layout(false);<o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">或者直接在模板文件的开头加上<span lang="EN-US">{__NOLAYOUT__} </span>标签:<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><b><span style="font-size:12.0pt;font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;
color:#525252;mso-font-kerning:0pt">(三)</span></b><b><span style="font-size:11.5pt;font-family:MicrosoftYaHeiLight;
mso-bidi-font-family:MicrosoftYaHeiLight;color:#222222;mso-font-kerning:0pt">如果想动态控制模板文件使用布局,则可以在控制器中使用:</span></b><b><span lang="EN-US" style="font-size:12.0pt;
font-family:彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:
0pt"><o:p></o:p></span></b></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">$this->view->engine->layout('layout','');<o:p></o:p></span></p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:12.0pt;font-family:
彩虹粗仿宋;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">return
$this->fetch();<o:p></o:p></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">注意:这里调用的是<span lang="EN-US">this->view->engine </span>对象的<span lang="EN-US">layout </span>方法,并不是所有的模板引擎都支持布局<span lang="EN-US"><o:p></o:p></span></span></p><p class="MsoNormal" align="left"><span style="font-size:12.0pt;font-family:彩虹粗仿宋;
mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:0pt">功能,如果你使用的是其它的模板引擎,可能不提供<span lang="EN-US">layout </span>方法。<span lang="EN-US"><o:p></o:p></span></span></p><p>
</p><p class="MsoNormal" align="left"><span lang="EN-US" style="font-size:11.0pt;font-family:
MicrosoftYaHei;mso-bidi-font-family:MicrosoftYaHei;color:#525252;mso-font-kerning:
0pt"><o:p> </o:p></span></p>
页:
[1]