使用TYPO3 extbase流体列出文件和文件夹?

时间:2018-03-06 14:36:36

标签: typo3 fluid extbase

我有像

这样的文件数组
'file1.pdf',
'file2.pdf',
'file3.JPG',
'Folder1/file1.pdf',
'Folder1/Subfolder1/Subfolder-file1.txt',
'Folder2/text.txt',
'Folder2/file2.pdf'

获取文件和文件夹列表我使用以下流体

<f:for each="{files}" as="userFile">
  <f:if condition="{userFile -> myext:explode(delimiter:'/') -> f:count()} == 1">
  <f:then>
    <a href="{userDirectory}{userFile}" target="_blank">{userFile}</a><br />
  </f:then>
  <f:else>
   <div class="folder">
    <f:for each="{userFile -> myext:explode(delimiter:'/')}" as="segment" iteration="itemIteration">
    <f:if condition="{itemIteration.isFirst}">
      <f:then>{segment}</f:then>
      <f:else><a href="{userDirectory}{userFile}" target="_blank">{segment}</a><br /></f:else>              
    </f:if>
   </f:for> 
  </div>    
 </f:else>
</f:if>
</f:for>    

我使用自己的爆炸视图助手

我只获得列表文件和文件夹

<a href="">file1.pdf</a>
<a href="">file2.pdf</a>
<a href="">file3.JPG</a>
  <div class="folder">Folder1</div>
    <a href="">file1.pdf</a>
  <div class="folder">Folder1</div>
   <a href="">Subfolder1 
     <a href="">Subfolder-file1.txt</a>

<div class="folder">Folder2</div>
  <a href="">text.txt</a>
<div class="folder">Folder2</div>
 <a href="">file2.pdf</a>

我如何获得像流体一样的列表?

<a href="">file1.pdf</a>
<a href="">file2.pdf</a>
<a href="">file3.JPG</a>

<div class="folder">Folder1</div>
  <a href="">file1.pdf</a>
  Subfolder-file1.txt
    <a href="">Subfolder-file1.txt</a>

<div class="folder">Folder2</div>
 <a href="">text.txt</a>
 <a href="">file2.pdf</a>

有可能吗?

1 个答案:

答案 0 :(得分:2)

在Extbase控制器中,您可以使用TYPO3\CMS\Core\Resource\ResourceFactory获取文件夹:

$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
// Format [ID OF STORAGE]:[FOLDER]
$folder          = $resourceFactory->getFolderObjectFromCombinedIdentifier('1:my/directory/to/scan');
$this->view->assign('folder', $folder);

现在你可以在流体中使用folowing partial来走文件夹了:

<强> Partial/FolderRecusive.html

<f:for each="{folder.files}" as="file">
  <a href={file.publicUrl}>{file.name}</a>
</f:for>
<f:for each={folder.subFolders} as="subFolder">
  <f:if condition="{subFolder.files -> f:count()} > 0 OR {subFolder.subFolders -> f:count()} > 0">
    <div class="folder">{subFolder.name}</div>
    <f:render partial="FolderRecursive" arguments="{folder:subFolder}" />
  </f:if>
</f:for>

在你的模板中输入这样的内容来显示文件夹:

<f:render partial="FolderRecursive" arguments="{folder:folder}" />