[FLOW3-general] Fluid: call a property by name with an own argument
Jens Hopp
flow3 at hopp-it.de
Thu Nov 3 15:35:40 CET 2011
On Wed, 02 Nov 2011 09:34:20 +0100, Bastian Waidelich wrote:
> Jens wrote:
>
> Hi Jens,
>
>> I would like to do something like this:
>> <p>{myEntity.{anyPropertyName}}</p>
>
> That's currently not supported (see [1]).
>
>> My example will not be rendered at all. Is there a way to get it?
>
> I would be interested in the concrete example. Usually you want to put
> such logic in your domain model. But as the FAQ explains, you can work
> around this with a small ViewHelper.
>
> Best,
> Bastian
>
> [1]
> http://forge.typo3.org/projects/typo3v4-mvc/wiki/FAQ#How-can-I-use-
dynamic-array-indexes
Hi Bastian,
I am thinking about rendering properties of a certain type (for example
"string" or "date") with a partial specially for this type. So I would
have partials for string, integer, date, boolean...
Perhaps ViewHelpers for every type would be better. I still did not
decide...
A workaround could be this:
class PropertyViewHelper extends \TYPO3\Fluid\Core\ViewHelper
\AbstractViewHelper {
/**
* @param void $entity An arbitrary entity
* @param string $propertyName
*/
public function render($entity, $propertyName) {
$getterName = 'get' . ucfirst($propertyName);
return $entity->$getterName();
}
}
The basic problem is how to put parameters into a method call in Fluid.
See Mathias Bolt Lesniak's post "Fluid: condition with arguments" from
November 3rd 11:30. This is a related topic.
Cheers
Jens
More information about the FLOW3-general
mailing list