[TYPO3-mvc] Howto call a ViewHelper like f:link.action in my own view helper class?
Franz Koch
typo3.RemoveForMessage at elements-net.de
Fri Jan 21 18:23:20 CET 2011
Hey,
> so the subject says it all :-)
and a little search on the list would have given you the answer for
that. This question has been asked and answered just 3 days ago - but
the answer is most likely not what you wanted to hear ;)
> Now if I show the customer list, I want to show the list of services
> that where addressed by the projects done for that customer.
...
> I thought of another way to get the information: storing all services
> that were provided for that customer in a services field of the
> customer object and then use the f:for view helper instead of a self
> written one. But I can't figure out how to tell extbase to read that
> information from the DB. (For the viewhelper I had to use a
> $query->statement()).
That depends. It it is possible for you to create a DB relation between
services and customers extbase would fetch and store the services in
your services property of the customer. If that's not possible or not
intended, I see two solutions:
a) call the repository inside the properties getter
b) use your existing viewHelper to resolve the services, assign those
services to the templateVariableContainer (just like you would assign a
new variable to the view from within your controller) and then render
the viewHelpers children, which allows you to process the services
however you like.
Example for b):
--- in your viewHelper ---------------
/**
* proper annotations
*/
public function render(Tx_YourExt_Domain_Model_Customer $customer, $as) {
// fetch the services - however you currently do it is fine
$services =
$this->serviceRepository->findByProjects($customer->getProjects());
// add the services as variable to your templates
$this->templateVariableContainer->add($as, $services);
// render child tags
$output = $this->renderChildren();
// cleanup (this in mandatory)
$this->templateVariableContainer->remove($as);
}
return $output;
--- in your template ------------------
<foo:yourViewHelper customer="{customer}" as="services">
<f:for each="{services}" as="service">
<f:link.action .....>
</f:for>
</foo>
---------------------------------------
For further details, just have a look at the "groupedFor" viewHelper of
Fluid, or the "alias" viewHelper which are basically doing what you need.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list