Display a list of Items in a folder


This snippet shows how to the use the macro viewtool's fileRepository method to build a list of files and folders in a folder.  This is the same viewtool that the fileRepository macro uses.  You have to get the folders and files separately. 

The objects in the lists are:

Folder Objects -
File Objects -


${esc.hash}set (${esc.dollar}foldersList = ${esc.dollar}macro.getfileRepository("/demos/", "true", ${esc.dollar}request))
${esc.hash}set (${esc.dollar}filesList = ${esc.dollar}macro.getfileRepository("/demos/", "false", ${esc.dollar}request))

<h2> Folders </h2>
${esc.hash}foreach(${esc.dollar}folder in ${esc.dollar}foldersList)
  <li> ${esc.dollar}folder.title - ${esc.dollar}folder.path </li>

<h2> Files </h2>
${esc.hash}foreach(${esc.dollar}file in ${esc.dollar}filesList)
  <li> ${esc.dollar}file.title - ${esc.dollar}{file.path}${esc.dollar}{file.fileName} </li>

Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor