So with these 3 bits
$view->assign($segments);
This assigns variables to the view class from the $segments variables correct ie
$segments->section and in the main template it would be {section}
$content = $view->render('index.phtml');
So the main template is rendered in the plugin instead ?
$response->setBody($content); // overwrites named segments
so the response body is the rendered main template with the sections rendered
aswell ?
Matthew Weier O'Phinney wrote:
-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Tuesday, 07 August 2007, 11:54 PM +1000):
Hi there im having some problems which ive managed to hack up. Id like
to be able to render a different template into a template variable
called {content} so then all i need is one main index template and each
controller / action can set a different content placeholder. The only
way i can do it for the moment is rendering a template to a variable
$this->view->content, would this be ok to do ?
$this->tpl = $this->view->getEngine();
$this->tpl->compile('sectionBody.html');
$this->view->content = $this->tpl->bufferedOutputObject($this->view);
$this->render("index", null, true);
It basically gets the view engine which is the flexy template engine,
compiles a section body as a string back to $this->view->content and it
will display in the variable within the index view script. If there is a
better way to do this let me know.
One method I and others have used is to render to named segments in the
response object -- that's what the second argument to render is. That
way, you can collate all your various content from different actions in
the response object, and then pull it out to fill in another template.
As an example, in your code above, I'd do something like:
$this->render('sectionBody', 'section'); // renders to 'section'
// response segment
And then create a dispatchLoopShutdown plugin:
class TwoStepView extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopShutdown()
{
$response = $this->getResponse();
$segments = $response->getBody(true);
// instantiate view in here somewhere...
$view->assign($segments);
$content = $view->render('index.phtml');
$response->setBody($content); // overwrites named segments
}
}
Hope that makes sense.