Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing additional parameters to the Zend partialLoop View Helper

In a Zend view I can apply a partial template to an iterable element as follows:

$this->partialLoop('template.phtml', $iterable);

However inside the template, only the elements of the $iterable are available, is there another way of passing extra data to the partial?

like image 509
Ciaran McNulty Avatar asked Nov 04 '09 10:11

Ciaran McNulty


2 Answers

Later I found (insert in partial):

$this->getHelper('PartialLoop')->view->otherVariable; 
like image 188
Kamil Nowak Avatar answered Sep 22 '22 01:09

Kamil Nowak


Inside the partial, you can access all of your view variables with:

$this->partialLoop()->view->myVariable

where myVariable is a normal view variable ($this->view->myVariable in the controller or $this->myVariable in the view, which it's actually the same thing). Basically, you retrieve the PartialLoop() object, then the view which called it, and then the variable itself.

This, though, will probably impact performance (and I don't think it's really MVC friendly...) But, hey: it works. :)

An example here: Hardcode.nl == Joris Osterhaus

like image 42
Bruno Belotti Avatar answered Sep 26 '22 01:09

Bruno Belotti