SW-X的模板引擎内置了布局模板功能支持,可以方便的实现模板布局以及布局嵌套功能。
需要在/config/view.php
配置文件中,将layout_on
项改为true
,layout_name
为布局文件路由。
开启layout_on
后,我们的模板渲染顺序会发生变化,例如我们以为index/index
路由视图为例。
下面是一个典型的layout.html
模板的写法:
{include file="public/header" /}
{__CONTENT__}
{include file="public/footer" /}
经过上面布局文件的解析后,解析顺序则为:
先include
了app/view/public/header.html
文件。
再include
,app/view/index/index.html
文件,并将其最终解析的内容替换到{__CONTENT__}
关键字。
最后再include
,app/view/public/footer.html
文件。