dotCMS combo-box from pullContent macro

In dotCMS, it's very easy to build a combo-box (a.k.a. SELECT or drop-down) from content drawn from the #pullContent() macro. Below is how to do it.

## Build a combo-box from content of a given Structure.
## $limit - Max number of results (0 for all results)
## $structure - inode of the structure
## $sortField - Results will be sorted by this field.
#macro( writeSelectAnyStructure $structure $sortField $limit)
   #pullContent("+type:content +live:true +structureInode:$structure" "$limit" "$sortField")
   <select id="qt$structureInode" name="qt$structureInode">
      <option value=""></option>
      #foreach($content in $list)
         #if($UtilMethods.isSet($!content.title))
            <option value="$!content.inode">$!content.title</option>
         #else
            <option value="$!content.inode">$!content.name</option>
         #end
      #end
   </select>
#end

My dotCMS notes.

Popular Posts