0
我正在用gridelments創建一個內容元素,我需要直接從子元素呈現一些數據。像「bodytext」或「header」這樣的字段沒有問題。但資產只給我一個計數器,而不是一個參考或路徑。
所以最大的問題是:我如何渲染孩子們的資產圖片?TYPO3 Gridelements。呈現來自子項的資產
我正在用gridelments創建一個內容元素,我需要直接從子元素呈現一些數據。像「bodytext」或「header」這樣的字段沒有問題。但資產只給我一個計數器,而不是一個參考或路徑。
所以最大的問題是:我如何渲染孩子們的資產圖片?TYPO3 Gridelements。呈現來自子項的資產
我可以分享一個VH我只是做了
<?php
namespace GeorgRinger\Theme\ViewHelpers;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Frontend\Resource\FileCollector;
class FalViewHelper extends AbstractViewHelper
{
/**
* @var boolean
*/
protected $escapeOutput = FALSE;
/**
* @param string $table
* @param string $field
* @param string $id
* @param string $as
* @return string
*/
public function render($table, $field, $id, $as = 'references')
{
$row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $table, 'uid=' . (int)$id);
if (!$row) {
return '';
}
$fileCollector = GeneralUtility::makeInstance(FileCollector::class);
$fileCollector->addFilesFromRelation($table, $field, $row);
$this->templateVariableContainer->add($as, $fileCollector->getFiles());
$output = $this->renderChildren();
$this->templateVariableContainer->remove($as);
return $output;
}
/**
* @return DatabaseConnection
*/
protected function getDatabaseConnection()
{
return $GLOBALS['TYPO3_DB'];
}
}
當然,你需要採取的namspace。
用法是
<theme:fal table="tt_content" field="assets" id=" => the id <= ">
<f:debug>{references}</f:debug>
</theme:fal>