Back

Loop through numbered fields

Description

If you have multiple fields or groups of fields that are similar (i.e. "Image 1," "Image 1 Caption," "Image 2," "Image 2 Caption"), you should write your velocity code once to put them into your page instead of repeating yourself for each one. You can do this with a combination of a "foreach" loop, and a "get()" with the name of the field.

Code

#foreach($thing in $dotcontent.pull("+structureName:EbiblestudyLesson",10,"modDate desc"))
        #foreach($num in [1..3])
                #set($fieldname = "worksheet$!{num}")
                $thing.get($fieldname).rawUri
        #end
#end