TP5 template cyclic output label volist

VOLIST tag
volist tag is generally for outputting result of the query data set (select methods), the result is usually the model select method returns a two-dimensional array, tags may be used directly volist output. First template assignment in the controller:

$list = User::all();
$this->assign('list',$list);

Is defined as the template, the output of the cycle number and the name of the user:

{volist name="list" id="vo"}
{$vo.id}:{$vo.name}<br/>
{/volist}

Volist tag name attribute indicates the name of the template variable assignment, and therefore not free to change in the template file. id represents the current loop variable, you can optionally specify, but make sure not to name attribute of conflict, such as:

{volist name="list" id="data"}
{$data.id}:{$data.name}<br/>
{/volist}

Support part data output of the query results, such as the output of 5 to 15 recorded therein

{volist name="list" id="vo" offset="5" length='10'}
{$vo.name}
{/volist}

The even record

{volist name="list" id="vo" mod="2" }
{eq name="mod" value="1"}{$vo.name}{/eq}
{/volist}

Mod property and for controlling the recording of a certain wrap, for example:

{volist name="list" id="vo" mod="5" }
{$vo.name}
{eq name="mod" value="4"}<br/>{/eq}
{/volist}

It is empty output tips:

{volist name="list" id="vo" empty="暂时没有数据" }
{$vo.id}|{$vo.name}
{/volist}

empty property does not support directly into the HTML syntax, but supports variable output, for example:

$this->assign('empty','<span class="empty">没有数据</span>');
$this->assign('list',$list);

Then use the template:

{volist name="list" id="vo" empty="$empty" }
{$vo.id}|{$vo.name}
{/volist}

Output loop variable:

{volist name="list" id="vo" key="k" }
{$k}.{$vo.name}
{/volist}

If no key attributes, default loop variable i, for example:

{volist name="list" id="vo"  }
{$i}.{$vo.name}
{/volist}

To the output of the array index, may be used as key variables, and loop variable difference is that the data itself is determined by the key, rather than the control cycle, for example:

{volist name="list" id="vo"  }
{$key}.{$vo.name}
{/volist}

Templates can be used directly in the function setting data sets without requiring assignment variables passed to the template data set in the control variable, such as:

{volist name=":fun('arg')" id="vo"}
{$vo.name}
{/volist}

FOREACH label
similar to the foreach tag and label volist, just more simple, not too many additional attributes, the simplest usage is:

{foreach $list as $vo} 
    {$vo.id}:{$vo.name}
{/foreach}
该用法解析后是最简洁的。

You can also use the following usage:

{foreach name="list" item="vo"}
    {$vo.id}:{$vo.name}
{/foreach}
name表示数据源 item表示循环变量。

Index may be output, as follows:

{foreach name="list" item="vo" }
    {$key}|{$vo}
{/foreach}
也可以定义索引的变量名

{foreach name="list" item="vo" key="k" }
   {$k}|{$vo}
{/foreach}

FOR Label
Usage:

{for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" }
{/for}

Start value, end value, step value and can support variable loop variable, start and end values ​​are necessary, others are optional. The default value is the comparison lt, name of the default value is i, the default value of the step value is 1, for example as follows:

{for start="1" end="100"}
{$i}
{/for}

The code is parsed

for ($i=1;$i<100;$i+=1){
    echo $i;
} 
Published 201 original articles · won praise 699 · views 270 000 +

Guess you like

Origin blog.csdn.net/weixin_44535476/article/details/100973993