Correction status:Uncorrected
Teacher's comments:
控制器
<?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>
点击 "运行实例" 按钮查看在线实例