Blogger Information
Blog 8
fans 0
comment 0
visits 5872
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模板赋值与模板内容过滤与替换技术,以及模板动态布局与模板继承技术-2018年5月29日
往昔流逝的博客
Original
880 people have browsed it
  1. 模板赋值与模板内容过滤与替换技术

    控制器代码:

public function replace(){
   $this->view->name = 'Lin';
   $this->view->salary = '8000';
   $filter = function ($content){
       return str_replace('Lin','GG', $content);
   };
  return $this->filter($filter)->fetch();
}

view视图replace代码:

我的姓名:{$name}
我的工资:{$salary}



  1. 模板动态布局与模板继承技术

    模板动态布局

    在view视图下新建一个layout.html,代码:

    {include file="public/header" /}
       {__CONTENT__}
    {include file="public/footer" /}

    然后在控制器Users代码:

    public function layout_list(){
       /*
        * 1.全局配置
        *config/temaplate.php
        *   //模板布局配置  'layout_on' =>true,   'layout_name' => 'layout'
        * 2.模板表签进行配置
        *
        * 3.动态配置
        */
       //开启布局
       $this->view->engine->layout(true);
      return $this->view->fetch('layout');
    }

    最后view/layout_list.html代码:

    {//layout name="layout" /}
    {//__NOLAYOUT__}<!--关闭模板-->

    <div class="main">主体</div>

    模板继承技术

    首先在view视图下新建一个base.html 代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="UTF-8">
       <title>模板继承</title>
    </head>
    <body>
       {block name="header"}
           {include file="public/header" /}
       {/block}
           {block name="main"}主体部分{/block}
       {block name="footer"}
           {include file="public/footer" /}
       {/block}
    </body>
    </html>

    控制器代码:

    public function block(){
       return $this->view->fetch();
    }

    view\Users\block.html 代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="UTF-8">
       <title>模板继承</title>
    </head>
    <body>
       {extend name="base" /}
       {//将main区块进行重写}
           {block name="main"}
             {__block__} 部分   <!--显示父区块的内容-->

    {/block}
    </body>
    </html>

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