ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
这种方式仅需在项目配置文件中添加相关的布局模板配置,就可以简单实现模板布局功能,比较适用于全站使用相同布局的情况,需要配置开启LAYOUT\_ON 参数(默认不开启),并且设置布局入口文件名 LAYOUT\_NAME(默认为layout)。 'LAYOUT\_ON'=>true, 'LAYOUT\_NAME'=>'layout', 'LAYOUT\_ON'=>true, 'LAYOUT\_NAME'=>'layout', 开启LAYOUT\_ON后,我们的模板渲染流程就有所变化,例如: namespace Home\\Controller; use Think\\Controller; Class UserController extends Controller{ Public function add() { $this->display('add'); } } namespace Home\\Controller; use Think\\Controller; Class UserController extends Controller{ Public function add() { $this->display('add'); } } 在不开启LAYOUT\_ON布局模板之前,会直接渲染 Application/Home/View/User/add.html 模板文件, 开启之后,首先会渲染 Application/Home/View/layout.html 模板,布局模板的写法和其他模板的写法类似,本身也可以支持所有的模板标签以及包含文件,区别在于有一个特定的输出替换变量 { CONTENT } ,例如,下面是一个典型的layout.html模板的写法: <include file="Public:header" /> { CONTENT } <include file="Public:footer" /> <include file="Public:header" /> { CONTENT } <include file="Public:footer" /> 读取layout模板之后,会再解析件的{CONTENT} 特定字符串。 User/add.html User/add.html 模板文件,并把解析后的内容替换到layout布局模板文 当然可以通过设置来改变这个特定的替换字符串,例如: 'TMPL\_LAYOUT\_ITEM' => '{ REPLACE }' 'TMPL\_LAYOUT\_ITEM' => '{ REPLACE }' 一个布局模板同时只能有一个特定替换字符串。 采用这种布局方式的情况下,一旦User/add.html 模板文件或者layout.html布局模板文件发生修改,都会导致模板重新编译。 如果需要指定其他位置的布局模板,可以使用: 'LAYOUT\_NAME'=>'Layout/layoutname', 'LAYOUT\_NAME'=>'Layout/layoutname', 就表示采用 Application/Home/View/Layout/layoutname.html Application/Home/View/Layout/layoutname.html 如果某些页面不需要使用布局模板功能,可以在模板文件开头加上 作为布局模板。 字符串。 { NOLAYOUT } { NOLAYOUT } 如果上面的User/add.html 模板文件里面包含有进行布局模板解析。 { NOLAYOUT } { NOLAYOUT } ,则即使当前开启布局模板,也不会