Martin
Martin

Reputation: 4330

Access dynamic object property in Typo3 Fluid template

I have an object in a Typo3 Fluid template and want to access a property on it, but the name of the property is in a variable someProperty:

<f:if condition="searchObject.{someProperty}">
        Found!
</f:if>

Because this does not work: Is there a built in way to access a property by variable?

Upvotes: 3

Views: 3406

Answers (3)

Andr&#225;s Ott&#243;
Andr&#225;s Ott&#243;

Reputation: 7695

You can give a chance to fedex Fluid viewhelper collection and its v:var.get viewhelper.

Or check the other viewhelpers in here. If you do not find a suitable one, you can write your own for this functionality based on some example here.

UPDATE:

Since this is an old question to TYPO3 6.2 it is the time to update it to the current standards. (See also the answer of Claus Due:

For the current LTS: TYPO3 9.5, you can use simple:

{searchObject.{someProperty}}

Upvotes: 6

Claus Due
Claus Due

Reputation: 4261

In Fluid standalone and TYPO3v8 and upward:

{array.{variableContainingKey}}.

Upvotes: 2

Wipster
Wipster

Reputation: 1570

The point notation actually is the correct way to access a property. What do you mean by dynamic? Can be null? Have you tried the following?

<f:if condition="<f:count>{searchObject.someProperty}</f:count>">
    Found!
</f:if>

Or maybe just:

<f:if condition="{searchObject.someProperty}">
    Found!
</f:if>

Upvotes: 0

Related Questions