Verification method for judging the last record of volist loop in ThinkPHP template

  • 2021-07-06 10:22:04
  • OfStack

For friends who have used smarty and developed php, they should all know that judging whether foreach loop is the last one in smarty template can use $smarty. foreach. name. last to judge whether the loop reaches the last record. The common loop in thinkphp template is volist, but the attributes of the last record are not directly judged in various attributes of volist, so how to judge in thinkphp? The following code can realize the last record of volist break in ThinkPHP.
Example code is as follows, readers can experience it by themselves.


<volist name='lists' id='list'>
<li <if condition="$i eq count($lists)">class="last"</if>>
<a href="https://www.ofstack.com/"> Script House </a>
</li>
</volist>

The $i in the above code snippet is a count variable in the volist loop, and the default name is $i, so it can be used without declaration.


Related articles: