Reputation: 18006
I want to render a different
view in my action
, pass data from action to that view and get its output in a variable.
I know that
$output = $this->view->render('path/to/script');
render different view script and returns output. But I also want to pass data to this script from my action but not succeeded so far. I have used
$this->view->data = $data
But it doesn't send data to this script.
Can any one guide how can I do it?
Upvotes: 2
Views: 5332
Reputation: 2143
You can pass an array of data to the view script:
$this->view->render('path/to/script/script', array('someValue' => true));
Access it in the view script with:
<?= $this->someValue ?>
EDIT: In a controller I always use...
$this->view->assign('someValue', 'data');
EDIT: With layout pattern... You need to set a variable in the controller for the path of the view script you want to use in the layout template and any variables/data you want passing to the view partial.
In controller:
$this->view->assign('partialPath', 'path/to/partial');
$this->view->assign('partialdata', 'value');
In Layout:
$this->view->render($this->partialPath, $this->partialData) //renders partial and passes data
In partial:
<?= $this->partialData ?> // echos data
Upvotes: 4