[TYPO3-mvc] Fluid - accessing an object property by a dynamic index

Bastian Waidelich bastian at typo3.org
Tue Sep 14 18:28:01 CEST 2010


Alexander Dick wrote:

Hi Alexander,

> I wonder if it is possible to access a template object by a dynamic index:

This is not possible with the current syntax and I doubt that it will 
come. See http://forge.typo3.org/issues/7618 for more informations.

But there is already a ViewHelper on it's way that will make this 
possible. It will take a while probably until it's in the core, but you 
can already implement it yourself. It looks something like

class Tx_YourExt_ViewHelpers_PropertyViewHelper extends 
Tx_Fluid_Core_ViewHelper_AbstractViewHelper {

	/**
	* @param string $propertyName
	* @param mixed $object
	* @return mixed
	*/
	public function render($propertyName, $object = NULL) {
		if ($object === NULL) {
			$object = $this->renderChildren();
		}
		return Tx_Extbase_Reflection_ObjectAccess::getPropertyPath($object, 
$propertyName);
	}
}

and you can use it like
{object -> f:property(propertyName: foo)}

HTH,
Bastian


More information about the TYPO3-project-typo3v4mvc mailing list