Blogger Information
Blog 64
fans 2
comment 3
visits 75757
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模板赋值过滤替换,动态模板-模板继承—2018年5月30日14:56:54
清雨的博客
Original
1079 people have browsed it

控制器

实例

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

class Index extends Controller
{
	// 模板赋值
	public function index()
    {
    	$this -> view -> name = '清雨';
    	return $this -> view -> fetch();
    }
    // 模板过滤
    public function demo()
    {
    	$this -> view -> assign('name','清雨');
    	$filter = function($content) {
    		return str_replace('清雨', '道古今',$content);
    	};
    	return $this->filter($filter)->fetch();
    }
    //模板布局
    public function demo1()
    {
    	return $this->view->engine->layout(true)->fetch('index@index/demo1');
    }
    // 模板继承
    public function demo2()
    {
    	return $this->view->fetch();
    }
}

运行实例 »

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

视图文件

index.html

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>模板赋值</title>
</head>
<body>
	我的姓名是:{$name}
</body>
</html>

运行实例 »

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

demo.html

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>模板过滤与替换</title>
</head>
<body>
	我的姓名是:{$name}
</body style="">
</html>

运行实例 »

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

demo1.html

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>模板动态布局</title>
	<style type="text/css">
	.main {
		width: 800px;
		height: 600px;
		margin:auto;
		background: lightgreen;
		text-align: center;
		line-height: 600px;
	}
</style>
</head>
<body>

{//layout name="layout" /}

{//__NOLAYOUT__}

<div class="main">主体内容</div>
</body>
</html>

运行实例 »

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

demo2.html

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>模板继承技术</title>
</head>
<body>
	{extend name="public/base" /}
	{block name="main"}
<h1 style="text-align: center">我是子模板的网站的主体部分</h1>
{/block}
</body>
</html>

运行实例 »

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

1.png

2.png

3.png

4.png

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