-- Dan Rossi <[EMAIL PROTECTED]> wrote
(on Wednesday, 08 August 2007, 01:09 AM +1000):
> 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}

I'm not sure how flexy works and how variables are referenced, but yes,
that's what I was thinking.  Zend_View_Abstract::assign() can take an
associative array as an argument (which is what response->getBody(true)
will return -- segment name ->content), and will assign the key/value
pairs to the view object.

>            $content = $view->render('index.phtml');
> 
> So the main template is rendered in the plugin instead ?

In the plugin, which will run *after* all actions have been completed
(which is when a dispatchLoopAction() plugin runs), yes -- it renders
the main template, with the various content pieces as assigned from the
response.

>            $response->setBody($content); // overwrites named segments
> 
> so the response body is the rendered main template with the sections 
> rendered aswell ?

Correct.

> 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.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to