is it possible to add multiple views in a array to a parent view in Zend Framework 2? For example:
childView.php
echo $this->data;
parentView.php:
foreach($this->views as $view)
echo '<div>'.$view.'</div>';
controller.php:
public function actionIndex(){
$children = array(1,2,3);
foreach($children as $child){
$childView = new ViewModel(array('data' => $child));
$childView->setTemplate('childView');
$childrenViews[] = $childView;
}
$view = new ViewModel();
$view->setTemplate('parentView');
// some function that adds the childrenViews to the parentView;
return $view;
}
Expected output: <div>1</div><div>2</div><div>3</div>
ps: It's dummy code so please ignore possible syntax errors.
Zf2TestApp-> zf2test.akrabat.com, particularly the multiple view models -> zf2test.akrabat.com/view/multipleViewModels. You can find the source on github (it's linked from the test app)