[TYPO3-english] Re: Extbase/Fluid extension: viewhelper to return associative array (T3 6.2.4)
Hagen Gebauer
gebauer at mpi-cbg.de
Tue Feb 24 08:48:42 CET 2015
Hi Joey,
thanks a lot! That's working brilliantly! Sometimes it's that simple :) Here's a short summary for everybody else to read:
The ViewHelper class:
namespace VendorName\ExtensionName\ViewHelpers;
class TestViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @param $arrayIndex string
*
* @return string
*/
public function render($arrayIndex) {
$returnArray = array('a' => 'abcdefg', 'b' => 'hijklmn');
return $returnArray[$arrayIndex];
}
}
calling an array element by its index in the Fluid template:
{namespace abc = VendorName\ExtensionName\ViewHelpers}
{abc:test(arrayIndex: 'b')} (calling by {namespace:viewhelper} and passing the array index)
will return:
hijklmn
More information about the TYPO3-english
mailing list