The volist if condition in thinkphp determines the last record

Source: Internet
Author: User
Tags foreach smarty template

Basic volist syntax

Volist tag (cyclic output data)
Close Non-closed labels
Attribute

Name (required): The data template variable to be output

Id (required): cyclic variable

Offset (optional): the offset of the data to be output.

Length (optional): the length of the output data.

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

Mod (optional): modulo the key value. The default value is 2.

Empty (optional): string to be empty


Anyone who has used smarty for php development should know whether the foreach loop in the smarty template can use $ smarty. foreach. name. last to determine whether the loop has reached the last record. How can we determine in thinkphp? In thinkphp templates, the common cycle is volist, and the volist attributes do not directly judge this. The following describes how to judge the last record in thinkphp volist.

Example

The code is as follows: Copy code

<Volist name = "list" id = "vo" offset = "5" length = '10'>
User Name: {$ vo ['username']} <br/>
Email: {$ vo ['email ']} <br/>
Registration time: {$ vo ['regdate'] | date = "Y-m-d H: I ",###}
<Hr/>
</Volist>

This makes it impossible to judge whether it is the last function. Baidu has such an example.

The code is as follows: Copy code


<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 way, we can use it normally. After talking about a bunch of things, let's get started.

The code is as follows: Copy code

<Volist name = 'lists' id = 'list'>
<Li <if condition = "$ I eq count ($ lists)"> class = "last" </if>
<A href = "/tag/thinkphp"> thinkphp tutorial </a>
</Li>
</Volist>

$ I in the above code snippet is a counting variable in the volist loop. The default name is $ I, so you can directly use it without declaration.

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.