thinkphp5 layout的使用以及关闭
2023-03-29 23:03:03
410
{{single.collect_count}}

     (思路:所有的页面先运行layout内的代码,在执行我们的特定字符串)

       1、创建一个模版

        

php think build --module admin

2、创建控制器

php think make:controller admin/lists --plain

3、在 admin/config.php 打开模版布局 添加如下代码

return ['template'=>['layout_on' =>true,'layout_name' =>'layout',]
4、创建一个独立的layout.html,这里放公共的前端代码,最后添加{__CONTENT__} (一个布局模板同时只能有一个特定替换字符串。)
5、要想单独某个页面不使用layout.html,有两种方法 直接在页面的头部添加 {__NOLAYOUT__} 或者
public function add(){// 临时关闭当前模板的布局功能 $this->view->engine->layout(false);return $this->display('add'); }}

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}