0

I'm creating a content Element with gridelments where i need to render some Data from the childs directly. There is no problem for fields like "bodytext" or "header". But the assets gives me only a counter, not a reference or path.
So the big question: How can i render the assets images from the childs?

enter image description here

kevinq
  • 109
  • 1
  • 17

1 Answers1

3

I can share a VH I just did

<?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'];
    }
}

Of course you need to adopt the namspace.

Usage would be

<theme:fal table="tt_content" field="assets" id=" => the id <= ">
  <f:debug>{references}</f:debug>
</theme:fal>
Georg Ringer
  • 7,779
  • 1
  • 16
  • 34