Blogger Information
Blog 65
fans 3
comment 4
visits 67730
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp5.1模板布局与继承
无耻的鱼
Original
3558 people have browsed it


QQ截图20180530141940.png

dome6实例

<?php
namespace app\index\controller;
// use think\View;
// use think\facade\View;
use think\Controller;

class Dome6 extends Controller
{
	function index()
	{
		return '你好';
	}

	// 模板布局
	/医院
	 * 1.全局配置:config/template 
	 *	 'layout_on' => true,
	 *	 'layout_name' => 'layout',
	 *
	 * 2.模板标签配置
	 * ①不依赖全局直接使用标签配置
	 * ②{layout name='布局名字'}
	 *
	 * 3.动态配置
	 * ①不要在模板配置文件中进行任何配置
	 * ②也不要添加任何标签
	 */
	function index4()
	{

		//开启布局
		// $this->view->engine->layout(true);
		// $this->view->engine->layout('layout','{__TXT__}');
		// return $this->fetch();  //index4


		// 合并上边的两句
		return $this->view
		->engine
		->layout(true)
		 ->fetch('Dome6/index4');

	}	



	//模板继承
	function index5()
	{

		// view下base
		//使用block   __block__可以使用模板内容
		return $this->fetch();
	}	 
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

index4.html

{//__NOLAYOUT__}<!-- 不使用layout -->
{//layout name='layout'}<div class="div" style="height: 400px;margin: 5px auto">我是中间</div>

index5.html

{extend name="base" /}
{block name="main"} <h2>你好</h2>{/block}

layout.html

{include file='template/header'}
{__CONTENT__}
{//__TXT__}
{include file='template/footer'}

base.html

{block name="header" } {include file='template/header' /}{/block}
{block name="main"} {/block}
{block name="footer"} {include file='template/footer'  /}{/block}

header.html

<style type="text/css">
 .div{
  width: 80%;
  height: 50px;
  margin: auto;
  background: #776693;
 }
</style>
<div class="div">我是顶部</div>

footer.html

<div class="div">我是底部</div>



Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post