Reputation: 99
I created a own viewhelper for my extension, which creates dynamic html code. I use
protected $escapeOutput = false;
in my extension. The html code for the Fluid viewhelper will be returned inside a string.
<f:image src='".$lPlay->getIfName()."' alt='Bild' height='50' />
But the Fluid viewhelper is not executed. In the source code of the web page I can see
<f:image src='fileadmin/user_upload/AlbumArtSmall.jpg' alt='Bild' height='50' />
What is my mistake or is it not possible to use a viewhelper inside a viewhelper, which creates html code.
Maybe I could call the fluid viewhelper inside my viewhelper directly with php. But I don't know how to do it.
public function render() {
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$lPlayC = $objectManager->get('HGA\\Mairlist\\Controller\\LastPlayController');
$lPlays = $lPlayC->sendAction();
$return = "\n<div class='lPlay'>\n";
$return .= "\t<table class='tx_mairlist' >\n";
$return .= "\t\t<tr class='header'>\n";
$return .= "\t\t\t<th colspan='3'><p class='header'>gerade gespielt</p></th>\n";
$return .= "\t\t</tr>\n";
$iPos = 1;
foreach ($lPlays as $lPlay) {
if ($iPos == 1) {
$class = "onair";
} else {
$class = "gone";
}
$return .= "<tr class='".$class."'>\n";
$date = $lPlay->getDate();
$temp = $date->format('H:i:s');
$return .= "<td class='time'> <p class='time'>".$temp."</p>\n";
$return .= "<p class='space'></br></p>\n";
$return .= "<p class='duration'>".$lPlay->getDuration()."</p>\n";
$return .= "</td>\n";
$return .= "<td> <f:image src='".$lPlay->getIfName()."' alt='Bild' height='50' /></td>\n";
$return .= "<td> <img src='".PATH_site.$lPlay->getIfName()."' alt='Bild' height='50' /></td>\n";
$return .= "<td class='info'><b>".$lPlay->getTitle()."</b></br><p class='artist'>".$lPlay->getArtist()."</p></td>\n";
$return .= "</tr>\n";
$iPos++;
}
$return .= "</table>\n";
$return .= "</div>\n";
error_log("ViewHelper: " . $return, 0);
return $return;
}
Upvotes: 0
Views: 641
Reputation: 4575
You should handle the HTML output in your template. You can add a variable to Fluid in your ViewHelper and render its children:
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$lPlayC = $objectManager->get('HGA\\Mairlist\\Controller\\LastPlayController');
$lPlays = $lPlayC->sendAction();
$this->templateVariableContainer->add('plays', $lPlays);
$output = $this->renderChildren();
$this->templateVariableContainer->remove('plays');
return $output;
In your template you can then use this ViewHelper like:
<ns:myViewHelper>
<div class="lPlay">
<table class="tx_mairlist">
<tr class="header">
<th colspan="3"><p class="header">gerade gespielt</p></th>
</tr>
<f:for each="{plays}" as="play" iteration="iteration">
<tr class="{f:if(condition: iteration.isFirst, then: 'onair', else: 'gone')}">
<td class="time">
<p class="time"><f:format.date format="H:i:s">{play.date}</f:format.date></p>
<p class="space"><br /></p>
<p class="duration">{play.duration}</p>
</td>
<td>
<f:image src="{play.ifName}" alt="Bild" height="50" />
</td>
<td class="info">
<b>{play.title}</b></br>
<p class="artist">{play.artist}</p>
</td>
</tr>
</f:for>
</table>
</div>
</ns:myViewHelper>
Upvotes: 0