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.