[TYPO3-mvc] Access built-in fluid viewhelpers from own viewhelper?

Sebastian Kurfürst sebastian at typo3.org
Fri Oct 15 08:10:28 CEST 2010


Hey Felix,

[small note: you just hijacked this thread, meaning that you replied to
an existing post instead of creating a new one. Not a big problem, but
makes your question a little more invisible ;-) ]

> Because I don't see any way to realize this within a Fluid template and its
> handy f:-tags I wrote my own viewhelper that should do the whole work. The
> viewhelper loops through the alphabet and arranges the data given through an
> argument.
So you use the viewhelper like: <my:alphabet objects="{myObjects}" />,
is this correct?

I'd suggest that you rewrite the ViewHelper so that you can do the
following:

<my:alphabet objects="{myObjects}"
objectsAsAlphabeticalList="alphabeticalObjects">

<f:for each="{alphabeticalObjects}" as="objectsWithACertainLetter"
key="letter">
<h1>{letter}</h1>

... another f:for loop for outputting the inner contents for one letter
</f:for>

</my:alphabet>

So basically I'd suggest that your ViewHelper only sorts the objects,
and groups them by category. Then, it can assign the array which looks like:
$objectArray = array('a' => array(... all objects starting with "a"
...), 'b' => ...)
to the template again, and rendering its children in the following way:


$this->templateVariableContainer->add($objectsAsAlphabeticalList,
$objectArray);
$output = $this->renderChildren(); // Render everything between opening
                                   //and closing tag
$this->templateVariableContainer->remove($objectsAsAlphabeticalList);
return $output;

Now that I think about it, this can almost be done with the
<f:groupedFor> ViewHelper. If you look at the documentation, I suppose
you only need to supply a getter inside your model which outputs the
first letter of the category you want to group by, and this should work
then.

> How can I access the f:link viewhelper from my own viewhelper? Or do I have
> to implement its functionality to my own viewhelper manually?
You should not use other ViewHelpers in your ViewHelper; but you can use
the UriBuilder to build URIs. You can get that with
$this->controllerContext->getUriBuilder() if I remember correctly.

Greets,
Sebastian


More information about the TYPO3-project-typo3v4mvc mailing list