# 页面渲染

居于简洁的原则出发，视图直接使用了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}>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.kaliphp.com/template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
