Pergunta

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.

Foi útil?

Solução 2

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

Outras dicas

If you are in the 2.0 series, I think you can just do a normal content pull and use the "path" property. Use something like in your query:

+path:/images/icons/*

So it would be:

#foreach($file in $dotcontent.pull("+structureName:FileAsset +path:/images/icons/* +conhost:HOST_IDENTIFIER",10,"title desc"))

     $file.title

#end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top