今天就跟大家聊聊有關如何在thinkphp5.1框架中使用模板布局與模板繼承,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
模板全局配置
配置文件template.php添加
//開啟全局模板布局 'layout_on' => true, //全局模板布局文件名 'layout_name' => 'layout'
模板布局
控制器中新建模板文件(application\index\controller\Demo\---test方法)
新建視圖文件(application\index\demo\test.html)
模板入口文件(application\index\view\index\index.html)
將公共模板頭部和尾部分別單獨放到一個html文件中(header.html、footer.html)【application\index\view\】
創建全局模板布局文件(layout.html)【application\index\view\】首先開啟布局 layout_on = true
{include file="header"/}
{__CONTENT__}//點位符,默認CONTENT,可在template.php文件中配置 'layout_item' => '{__TEXT__}'
{include file="footer"/}模板繼承
新建公用模板目錄(application\index\view\common)
分離頭部的尾部(header.html、footer.html)
公共模板文件(父模板文件中只能用include和block標簽)
{include file="common/header" /}
{block name="body"}
主體
{/block}
{block name="nav"}
導航
{/block}
{include file="common/footer" /}子模板文件(只能在block標簽內)
{extend name="public/base" /}
{block name="body"}
{__block__}//繼承父模板中內容
<h3>模板</h3>
{/block}
{block name="nav"}{/block}//清空父模板中內容看完上述內容,你們對如何在thinkphp5.1框架中使用模板布局與模板繼承有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。