批改状态:未批改
老师批语:

<?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>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号