velocitydotcms

How to get a plain list of files in velocity on a dotCMS system?


I am trying to get a plain list of files, meaning just the file names, of all the files in a directory using velocity in a dotCMS widget. I have tried the following, but it does not work.

#set ($fileRepository_showFolder="/mydepartment/content/")
#set ($fileRepository_filesList = $macro.getfileRepository($fileRepository_showFolder,
"false", $request))
#foreach ($file in $fileRepository_filesList)
$file.title <br>
#end

to test that I was getting the files, but it did not find any files.

#fileRepository("/mydepartment/content/")

Works but I don't want their file view widget just a list of files.

I have also tried

#getFilesFromFS("/mydepartment/content")

This does not work either. Again it gives me an empty list. If I use an empty string to the above macro I get four .jsp files as a result, but I don't know how to piont it at my content.

Additional information. I don't have full access to the system. The most technical access I have is to create velocity widgets.

Just to be clear on what I am looking for I would like to have a list of files I can iterate through using a foreach.


Solution

  • I got it working using the following code.

    #set($files = $navtool.nav)
    #set($children = $files.children)
    #foreach($ch in $children)
    $ch.title
    $ch
    #end
    
    $ch.title 
    

    outputs just the file (without the extension)

    $ch
    

    outputs the filename as a link to the file