Building a TYPO3 extension in Extbase/Fluid

ViewHelper returning multiple values

File paths are relative to the root of your extension /typo3conf/ext/your_extension/

/Classes/ViewHelpers/TestViewHelper.php

<?php
namespace VendorName\YourExtension\ViewHelpers;

use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class TestViewHelper extends AbstractViewHelper
{
        public function initializeArguments()
        {
                parent::initializeArguments();
                $this->registerArgument('arrayIndex', 'string', 'weblink text', true);
        }

        /**
         * @param string $arrayIndex
         *
         * @return string
         */

        public function render()
        {
                $arrayIndex = $this->arguments['arrayIndex'];

                $returnArray = array('a' => 'abcdefg', 'b' => 'hijklmn');
                return $returnArray[$arrayIndex];
        }
}

?>
        }
}

?>

The Fluid Template

/Resources/Private/Templates/…

{namespace someName = VendorName\YourExtension\ViewHelpers}
<strong>{someName:test(arrayIndex: 'b')}</strong> <!-- calling by {namespace:viewhelper} and passing the array index -->

This will return:
hijklmn