How to access properties of a FileReference Object in fluid
Asked Answered
R

1

15

Below you see the debug for an object of type FileReference in fluid. In fluid the debug looks like this: <f:debug>{fileReference}</f:debug>

The question is how do I access the properties highlighted in green, being width, height, and hovertext.

The original file is an image, so width & height are default T3 properties, hovertext has been added by my extension with it's own getter/setter.

I tried the following:

{fileReference.width}
{fileReference.mergedProperties.width}
{fileReference.originalResource.width}

No luck so far, what is the right way to access the values in mergedProperties?

Many Thanks

Florian

TYPO3 fluid Debug

Retrench answered 19/10, 2016 at 15:6 Comment(2)
Are you sure your file class extends from the default class?Zoi
Pretty sure yes, but even though, should that have any effect on the standard width & height attribute for images? Those have been added by the core team themselves, those should work in any case or am I missing something here?Retrench
M
41

The f:debug shows something similar to the var_dump function, so the properties of an object. In fluid you can only access the getter functions or if it is an array the values of the array. So if you write something like {fileReference.mergedProperties} the method getMergedProperties() is called if it is present.

Knowing that you can look inside the sysext/core/Classes/Resource/FileReference.php File and see what getters it has. We can quickly find the public function getProperties() that returns the merged properties you marked, so the right solution should be this:

{fileReference.properties.width}
Magnitogorsk answered 19/10, 2016 at 21:21 Comment(4)
Yes, it works. Thank you very much, that was incredibly helpful. You not only provided the solution to my problem, but know I know how that works and can look for myself the next time.Retrench
This answer and the question should be upvoted by anyone who sees it. It completely explains the details about the DebuggerUtility and Fluid (internally, Extbase) variable access. If you want to know every last detail about how Fluid accesses any variable, you may find vimeo.com/169551666 informative. But do upvote this answer and question!Vie
Once again, this is obligatory information that should be explained in the documentation.Lightfooted
Thanks. Just a note to people who don't get this immediately (including me): You can do this exact thing for other classes. If you i.e. want to get the title or the width of the file instead of filereference, just use {file.properties.width}Acrolein

© 2022 - 2024 — McMap. All rights reserved.