> For the complete documentation index, see [llms.txt](https://doc.kaliphp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.kaliphp.com/template.md).

# 页面渲染

居于简洁的原则出发，视图直接使用了Smarty模板引擎，在Smarty上做了二次开发，增加自由函数、自定义block标循环插件，操作十分简单。

视图层目录在`app/template/`下面，可以在`Action`层中通过`tpl::display()`方法输出模板

### 渲染参数

`display`方法只有一个参数，指定`template`文件

```
// 给模板变量赋值
tpl::assign('test', 1);
tpl::assign('path', '/test.png');
// 显示视图 app/template/main/test.tpl 
tpl::display('main/test');

/* app/template/main/test.tpl
返回:
<div class="container">
    <span> 1 </span>
    <img src="/test.png"/>
</div> */
<div class="container">
    <span> <{$test}> </span>
    <img src="<{$path}>"/>
</div>
```

### 自定义函数插件

对应文件为：`smarty_plugins/function.tagname.php`, 与普通函数调用不同之处是，这是属于动态触发的插件函数，而非自由函数。

```
<{myfunc att1=$arr.title att2='8'}>
```

### 自定义block标循环插件

对应文件为：`smarty_plugins/block.tagname.php`, 相当于函数返回foreach里的from值

```
<{myblock key=k item=v}>
    <{$k}> -- <{$v}>
<{/myblock}>
```
