Translations
Info
All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Extbase/ViewHelper

From TYPO3Wiki
Jump to: navigation, search

Class

Create the following file:

myExt/Classes/ViewHelpers/LinkViewHelper.php

In this example we do create a simple ViewHelper for rendering the link wizard in fluid.

PHP script:
namespace Vendor\Myext\ViewHelpers;
/**
 * Copyright notice
 * [...]
 */

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Class LinkViewHelper
 *
 * @package Vendor\Myext\ViewHelpers
 */
class LinkViewHelper extends AbstractViewHelper {

	/**
	 * @param string $url
	 * @return string
	 */
	public function render($url) {

		/** @var $contentObject \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
		$contentObject = $GLOBALS['TSFE']->cObj;

		return $contentObject->getTypoLink_URL($url);

	}

}

Use in fluid

XML / HTML:
{namespace myhelper=Vendor\Myext\ViewHelpers}

// Used "h-r-e-f" instead "href" since the typo3 wiki doesn't accepts <a> tags for reasons of safety
<a h-r-e-f="{myhelper:link(url: '{linkUrlFromTCA}')}">Testlink</a>