2008年12月8日星期一

Re: [fw-mvc] Using HeadLink from a view helper (in the layout)

What I do is break up the layout into two parts.  Render and capture the body and then insert into the layout, which simply renders the headers and the recently captured body.  That way, you can use all of the aggregators.

So, you're layout file will look something like:

<?php
    // Capture the body first - Can still utilize all of the helpers within body.phtml
    $this->placeholder('body')->set($this->render('body.phtml'));

    echo $this->docType();
?>

<html>
<head>
    <php...Render the headers...?>
</head>

<?php echo $this->placeholder('body'); ?>


Matthew Weier O'Phinney wrote:
-- Dodger <glen.84@gmail.com> wrote (on Monday, 08 December 2008, 09:18 AM -0800):   
The only problem with this is that there is no way of ensuring that a user of the view helper will place it correctly.     
 Well, that becomes an education issue, then. The fact of the matter is that the layout script is evaluated sequentially, just as any other view script. So, calls to an aggregator that occur after the aggregator has been rendered will have no effect.     
Matthew Weier O'Phinney-3 wrote:     
-- Dodger <glen.84@gmail.com> wrote (on Monday, 08 December 2008, 02:07 AM -0800):       
I have a view helper that is used in my layout file, which (among other things) adds CSS to the document head using the HeadLink helper. The problem is that the helper is using HeadLink *after* the layout calls "echo $this->headLink();", so the CSS is never output.  Is there no way of adding CSS to the head from within a layout file (after the document head)?  I would have liked to have avoided CSS in the body.         
Capture the return value of your view helper at the top of your layout script, and then echo it within the body:      <?  $foobar = $this->myHelper(); ?>     <?= $this->doctype() ?>     <html>     <head>         <?= $this->headTitle() ?>         <?= $this->headLink() ?>     </head>     <body>         <?= $this->layout()->content ?>         <?= $foobar ?>     </body>  --  Matthew Weier O'Phinney Software Architect       | matthew@zend.com Zend Framework           | http://framework.zend.com/         
--  View this message in context: http://www.nabble.com/Using-HeadLink-from-a-view-helper-%28in-the-layout%29-tp20892525p20899535.html Sent from the Zend MVC mailing list archive at Nabble.com.      
   

没有评论: