How to append hash tables in velocity template?

扶醉桌前 提交于 2019-11-29 17:28:20
Karma-yogi

Your code currently is over writing $foo each time and hence you are just getting the last value. You can use lists in velocity to achieve this. This might work:

#set($listOfMnames=[])
#set($listOfSubNames=[])

#foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
#set($foo=$listOfMnames.add($!{dun1.mname}))
#set($foo=$listOfSubNames.add($!{dun1.subname}))
#end

This way, you will end up with two lists 'listOfMnames' and 'listOfSubNames', both fully populated. You can later iterate through them to print/utilise their values.

This link will be helpful and tell you the purpose of using $foo which is not being used and just being assigned. Alternatively, you can also use velocity maps with proper key/val pairs but be sure to declare it before the loop begins.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!