ThinkPHP_5模板的包含和继承

ul.nav>li*4>a[href=""]{菜单$$}  sublime text 3快捷键

方法一:{block}{/block}

带可添加内容的坑的公共模板【common/base.html】
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>
    {block name="title"}
    ThinkPHP_5 index页
    {/block}
  </title>
</head>
<body>
  <div class="wrap">
    <div class="header">
      <!-- 模板引入 -->
      {include file="common/nav" /}
    </div>

    <div class="main">
      <div class="sidebar">

      </div>

      <div class="body">
        {block name="body"}

        {/block}
      </div>
    </div>

    <div class="footer">
      {block name="footer"}
      footer块【公共继承】
      {/block}
    </div>
  </div>
</body>
</html>


【view/index.html】
  <!-- 继承机制 -->
  {extend name="common/base" /}

  {block name="body"}
  这是index的body块
  {/block}

  {block name="footer"}
  这是index的{__block__}
  {/block}

方法二:layout方法

修改应用配置i文件

  新加链条配置

  'layout_on' => true,
  'layout_name' =>'layout',

如:

'template' => [
// 模板引擎类型 支持 php think 支持扩展
'type' => 'Think',
// 视图基础目录,配置目录为所有模块的视图起始目录
'view_base' => '',
// 当前模板的视图目录 留空为自动获取
'view_path' => '',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DS,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
'layout_on' => true,
'layout_name' =>'layout',
],

在view目录下创建 layout.html 文件

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <title>
    ThinkPHP_5  {$title} 
  </title>
</head>
<body>
  <div class="wrap">
    <div class="header">
      <!-- 模板引入 -->
      {include file="common/nav" /}
    </div>

    <div class="main">
      <div class="sidebar">

      </div>

      <div class="body">
        {__CONTENT__}  【 只能用{__CONTENT__} 】
      </div>
    </div>

    <div class="footer">
      footer
    </div>
  </div>
</body>
</html>

在view/index.html下可直接写内容

原文地址:https://www.cnblogs.com/Caveolae/p/7122245.html