Create and iterate through an array in Velocity Template Language

前端 未结 3 1702
悲哀的现实
悲哀的现实 2020-12-15 02:57

How to create an array in VTL and add contents to the array? Also how to retrieve the contents of the array by index?

3条回答
  •  太阳男子
    2020-12-15 03:16

    Creating an array is easy:

    #set($array = [])
    

    Putting an element into an array is also easy:

    $array.add(23)
    

    Getting an element from an array depends from your Velocity version. In Velocity 1.6 you must use

    $array.get($index)
    

    Since Velocity 1.7 you can use the classic form:

    $array[$index]
    

提交回复
热议问题