# volist 循环标签
## 循环标签
用于循环输出数组或者对象的属性,例如使用多文件、多图片、复选、键值对的组件时,在内容页调用该标签循环输出内容。
## 格式示例
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"Info.images"</span><span class="token1">}</span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"carousel-item {$currentstyle}"</span><span class="token">></span>
<span class="token"><</span>img src<span class="token">=</span><span class="token4">"{$item}"</span> class<span class="token">=</span><span class="token4">"d-block w-100"</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
## 参数
参数名称可选值默认值是否必填说明currentstyle-active-指定选中的class样式具体看下面示例current-1-指定第几个选中,默认active class给到第一个id-$item-指定循环里的变量名,例如id='obj',模板调用如:{$item.title} 变成 {$obj.title}name---传入数组、对象offset---从第几条开始循环length---循环次数,例如输出其中的第5~15条记录,offset="5" length='10'mod---取余运算empty---为空的时候输出提示key-i-指定循环变量,如果没有指定key属性的话,默认使用循环变量i## 参数说明
`currentstyle` 属性,用于图集数组在轮播图时进来页面看到的第一张图片,active 没有定义样式,需要自己定义。结合`current`属性,current=1,在第一次循环时currentstyle等于active,其他循环为空。如下:
```
<pre class="calibre16">```
<span class="token5">// current=2,只有循环到第二次时$currentstyle变量才有active值</span>
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> current<span class="token">=</span><span class="token4">"2"</span><span class="token1">}</span>
<span class="token"><</span>p class<span class="token">=</span><span class="token4">"{$currentstyle}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">}</span><span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`id` 属性,用于改变循环变量,默认是$item,例如改成$vo,无需加$
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> id<span class="token">=</span><span class="token4">"vo"</span> <span class="token1">}</span>
<span class="token"><</span>p<span class="token">></span><span class="token1">{</span>$vo<span class="token1">}</span><span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`name` 属性,传入要输出的变量名称,如上面,取的是自己添加的字段files(多文件数组类型)。除了变量,还支持调用方法如下:
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">":ceshi()"</span> id<span class="token">=</span><span class="token4">"vo"</span><span class="token1">}</span>
<span class="token"><</span>p<span class="token">></span><span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$vo<span class="token1">)</span><span class="token1">;</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span><span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`offset` 属性,用于限制从第几条开始循环,例如如下:结合`length`属性输出其中的第5~15条记录
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> offset<span class="token">=</span><span class="token4">"5"</span> length<span class="token">=</span><span class="token4">"10"</span><span class="token1">}</span>
<span class="token"><</span>p<span class="token">></span><span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$item<span class="token1">)</span><span class="token1">;</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span><span class="token"><</span><span class="token">/</span>p<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`mod`取余运算属性,使用该属性后,在循环模板里面得到{$mod}变量,里面的值等于循环变量`i%mod`,i是从1开始的,每循环一次i+1。
例如:mod="2",判断偶数奇数。用于每一行图片左右摆放样式不一样时可以使用。更多使用方式根据实际情况设置。
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> mod<span class="token">=</span><span class="token4">"2"</span><span class="token1">}</span>
<span class="token1">{</span>$i<span class="token1">}</span> <span class="token">-</span> <span class="token1">{</span>$mod<span class="token1">}</span>
<span class="token1">{</span><span class="token2">if</span> $mod<span class="token">==</span><span class="token3">1</span><span class="token1">}</span>偶数<span class="token1">{</span><span class="token2">else</span> <span class="token">/</span><span class="token1">}</span>奇数<span class="token1">{</span><span class="token">/</span><span class="token2">if</span><span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`empty`为空提示标签,不支持传入HTML,但可以传入变量
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> empty<span class="token">=</span><span class="token4">"没有更多数据了"</span><span class="token1">}</span>
<span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$item<span class="token1">)</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
传入变量
```
<pre class="calibre16">```
<span class="token1">{</span>php<span class="token1">}</span>$empty <span class="token">=</span> <span class="token4">'<p align="center">- 没有更多数据了 -</p>'</span><span class="token1">;</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span>
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> empty<span class="token">=</span><span class="token4">"$empty"</span><span class="token1">}</span>
<span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$item<span class="token1">)</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
`key` 循环变量属性,默认是i,从1开始,每循环一次增加1。
输出循环变量
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> <span class="token1">}</span>
<span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$i<span class="token1">)</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
改变循环变量
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> key<span class="token">=</span><span class="token4">"k"</span> <span class="token1">}</span>
<span class="token1">{</span>php<span class="token1">}</span><span class="token6">dump</span><span class="token1">(</span>$k<span class="token1">)</span><span class="token1">{</span><span class="token">/</span>php<span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
循环变量不是指数组索引值,数组索引值可以使用{$key}。
```
<pre class="calibre16">```
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"$Info.more.files"</span> <span class="token1">}</span>
<span class="token1">{</span>$key<span class="token1">}</span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
## 示例
- 设置第二张选中,选中的class 为:ac
有时候,我们的图集轮播图,需要默认显示第几张显示,可按一下设置参数,设置好后,将{$currentstyle}放入你想放入的class标签上即可。
```
<pre class="calibre20">```
<span class="token5">// Info.images 为内容里的图集,name不用加:$,可参考模板开发下的可用变量。</span>
<span class="token1">{</span>hkcms<span class="token1">:</span>volist name<span class="token">=</span><span class="token4">"Info.images"</span> currentstyle<span class="token">=</span><span class="token4">"ac"</span> current<span class="token">=</span><span class="token4">"2"</span><span class="token1">}</span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"carousel-item {$currentstyle}"</span><span class="token">></span>
<span class="token"><</span>img src<span class="token">=</span><span class="token4">"{$item}"</span> class<span class="token">=</span><span class="token4">"d-block w-100"</span><span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>volist<span class="token1">}</span>
```
```
- 简介
- 下载与安装配置
- 下载
- 虚拟主机安装
- 百度云虚拟主机
- 创业云虚拟主机
- Linux下宝塔安装
- 宝塔一键部署
- Windows下宝塔安装
- phpEnv下安装
- phpStudy下安装
- 伪静态(url重写)
- 安装系统
- 调试模式与env文件
- 重新安装与安装文件说明
- 后台使用帮助
- 后台入口文件
- 首页面板
- 配置中心
- 站点配置
- SEO设置
- SEO设置-静态生成
- 文档属性
- 站点模块
- V2.2.2版本 -
- V2.2.3版本 +
- 模型管理
- 栏目管理
- 字段类型与组件
- 前言
- 前端组件
- 验证规则
- text 单行文本
- textarea 多行文本
- radio 单选
- checkbox 复选
- select 下拉列表
- selects下拉列表(多)
- selectpage 动态下拉
- editor编辑器
- image图片
- images图片(多)
- number数字
- date日期
- datetime日期和时间
- downfile文件上传
- downfiles文件上传(多)
- array 数组(键值对)
- 内容管理
- 自定义URL
- 多语言
- 界面多语言
- 内容多语言
- 多语言URL地址
- 附件管理
- 应用中心
- 标签语法
- 标签使用必读
- 列表标签
- content 内容列表标签
- contentpage 内容列表分页
- wfpage 瀑布流分页
- filter 筛选标签
- order 排序标签
- 内容标签
- guestbook 留言(表单)标签(废弃)
- form 表单标签
- pre 上一篇标签
- next 下一篇标签
- prenext 上一篇下一篇(高级)标签
- fileinfo 获取附件信息(文件下载)
- 内容分页
- raw 格式化编辑器文本(即将废弃)
- 全局标签
- seo 标签
- channel 栏目标签
- arcone 获取单条文档
- breadcrumb 面包屑导航标签
- adv 站点模块标签
- date 日期格式化标签
- substr字符(标题)截取标签
- volist 循环标签
- language 获取语言列表标签
- query 查询数据库内容
- include 导入模板文件标签
- 原生PHP与php标签
- map生成位置地图
- thumb 生成缩略图
- addons 插件检测
- 标签管理
- taglist标签(获取标签列表)
- tagarclist根据标签获取文章内容列表
- 导入标签
- 模板开发
- 1. 创建模板
- 2. 模板目录结构
- 3. 模板描述文件(重要) info.ini
- 4. 变量输出格式
- 4. 模板变量
- 5. 获取站点配置
- 6. 模板界面多语言
- 7. 模板静态目录及调用静态文件
- 8. 模板定义插件事件
- 9. 模板搜索页
- 10. 模板配置JSON
- 11. 导入演示数据
- 12. 卸载删除演示数据
- 13. 模板文件打包
- 14. 整站源码打包
- 插件开发
- 1. 创建插件
- 2. 目录结构
- 3. 插件名称类
- 4. 插件信息(info.ini)
- 5. 插件事件
- 6. 配置文件
- 7. install 安装目录
- 8. 创建菜单
- 9. 插件控制器
- 10. 插件视图
- 10-1 插件主题化
- 11. 插件模型
- 12. 模型事件
- 13. 插件内置函数
- 13-1 插件函数库
- 14. 插件多语言
- 15. 插件中间件
- 16. 插件路由
- 17. 插件验证器
- 18. 标签库
- 19. 第三方类库
- 20. 数据库文件导入
- 插件打包
- 后台前端使用帮助
- 二次开发帮助(更新中)
- 后台前端开发帮助
- 路由(链接地址、访问规则)
- URL访问
- 路由定义
- URL生成
- 附录
- 数据字典
- 助手函数库