Feature #33215

RFC: Dynamic values in ObjectAccess paths

Added by Christopher Hlubek over 3 years ago. Updated over 1 year ago.

Status:New Start date:2012-01-16
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
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 arrays New 2012-08-23
related to TYPO3.Fluid - Feature #33394: Logical expression parser for BooleanNode Needs Feedback 2012-01-23

History

#1 Updated by Alexander Berl almost 3 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 almost 3 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 almost 3 years ago

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

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

Also available in: Atom PDF