Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluid: Directly access value of array returned by view helper

Tags:

typo3

fluid

I've got custom fluid ViewHelper that returns an array, and I'd like to access a value of this array directly in one command.

Currently I'm using two commands:

{vendor:helper() -> v:variable.set(name: 'data')}
Value of foo: {data.foo}

Is there a way to do this in a single command? v:variable.get does not seem suited for this task.

like image 407
cweiske Avatar asked Nov 20 '22 23:11

cweiske


1 Answers

As @Jpsy said, there is the VHS Variable / GetViewHelper.

But the usage should be {v:variable.get(name: '{vendor:helper()}.foo')}.

If you need the returned array of your viewhelper multiple times in your template, it's better to use it the way you already did. Because otherwise you would call the PHP method behind the viewhelper to build and return the array each time you want to access an index of an already previously built array again.

like image 147
Seika85 Avatar answered Nov 30 '22 22:11

Seika85