Judging the last record of volist if condition in thinkphp

Source: Internet
Author: User
Tags foreach count smarty template

Volist Basic Syntax

Volist label (circular output data)
Closed Non-closed label
Property

Name (required): Data template variable to output

ID (required): Loop variable

Offset (optional): Offset to output data

Length (optional): Lengths of output data

Key (optional): The key variable of the loop, the default value is I

MoD (optional): Modulo key value, defaults to 2

Empty (optional): If the data is displayed in an empty string

Friends who have used smarty for PHP development should know that the Smarty template determines whether the Foreach loop is the last one to use $ Smarty.foreach.name.last to determine whether the cycle to the last record, in the thinkphp How to judge? The common loops in thinkphp templates are volist, and Volist's various attributes do not directly judge this. Here's how to judge the last record in thinkphp volist.

Example

The code is as follows

<volist name= "list" id= "Vo" offset= "5" length= ' >
User name: {$vo [' username ']}<br/>
E-mail: {$vo [' email ']}<br/>
Registration time: {$vo [' regdate ']|date= ' y-m-d h:i ', ###}
</volist>

This is not a judge is not the last function, Baidu has such an example

The code is as follows


<volist name= "list" id= "Vo" >
<volist name= "Slist" id= "S" >
<if condition= "$s. SID eq $vo [' id '] ' >/or <if condition= $s [' Sid '] eq $vo [' id '] ' >
Content.....
</if>
</volist>
</volist>

This discovery is normal to use, said a bunch of crap, let's get to the point.

The code is as follows

<volist name= ' lists ' id= ' list ' >
<li <if condition= "$i eq count ($lists)" >class= "Last" </if>>
<a href= "/tag/thinkphp" >thinkphp tutorials </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 you can use it without declaring it directly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.