Feature #33215

RFC: Dynamic values in ObjectAccess paths

Added by Christopher Hlubek about 9 years ago. Updated almost 5 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2012-01-16
Due date:
% Done:

0%

Estimated time:
Has patch:
No

Description

Sometimes it's necessary to include a dynamic value from a Fluid variable inside an object access path. Some use cases would be:

  • Get the value of an array or object depending on a key in a foreach loop
  • ...

A possible syntax amendment could look like this:


<p>{myobject[propertyName]}</p>

Where propertyName is a template variable itself:


$this->view->assign('propertyName', 'foo');
$this->view->assign('myobject', $myObject);

In this context it would evaluate to the value of {myobject.foo}. This is consistent to the way JavaScript defines its object access syntax with variables.


Related issues

Related to TYPO3.Fluid - Feature #40081: Allow assigned variables as keys in arraysNew2012-08-23

Actions
Related to TYPO3.Fluid - Feature #33394: Logical expression parser for BooleanNodeNeeds FeedbackTobias Liebig2012-01-23

Actions
#1

Updated by Alexander Berl over 8 years ago

I had this requirement already (solved it by implementing an object-accessor viewhelper that gets an object path string as argument) and I like the general idea.

I'm not sure about the syntax though. What about {myobject.{propertyName}}?

#2

Updated by Christopher Hlubek over 8 years ago

Yeah, me too and I did it with a simple ViewHelper, too. But I really would not go for another nested curly braces syntax. We use them way too much right now and very inconsistent. The JavaScript / PHP offset access would be consisten with Eel and we could at one day switch to Eel for all Fluid Expressions, which could make Fluid much more expressive.

Alexander Berl wrote:

I had this requirement already (solved it by implementing an object-accessor viewhelper that gets an object path string as argument) and I like the general idea.

I'm not sure about the syntax though. What about {myobject.{propertyName}}?

#3

Updated by Christian Müller over 8 years ago

Would be nice to have that feature, I like the syntax suggestion with

<p>{myobject[propertyName]}</p>

#4

Updated by ondro no-lastname-given almost 5 years ago

Agree

+1

Also available in: Atom PDF