开发者

Extending Zend View Helper Placeholder

I was reading the manual about basic placeholder usage, and it has this example:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    // ...

    protected function _initSidebar()
    {
        $this->bootstrap('View');
        $view = $this->getResource('View');

        $view->placeholder('sidebar')
             // "prefix" -> markup to emit once before all items in collection
             ->setPrefix("<div class=\"sidebar\">\n    <div class=\"block\">\n")
             // "separator" -> markup to emit between items in a collection
             ->setSeparator("</div>\n    <div class=\"block\">\n")
             // "postfix" -> markup to emit 开发者_开发技巧once after all items in a collection
             ->setPostfix("</div>\n</div>");
    }

    // ...
}

I want to accomplish almost exactly that, but I'd like to conditionally add more class values to the repeating divs, at time of rendering if possible, when all the content is in the placeholder. One thing I specifically want to do is add the class of "first" to the first element and "last" to the last element. I assume that I'll have to extend the Zend_View_Helper_Placeholder class to accomplish this.


The string set with setSeparator() is what will be used to implode elements in a container. Either set it to an empty string or just leave out the call to setSeparator() and insert the separating divs along with your other content:

  <?php $this->placeholder('sidebar')->captureStart(); ?>

  <?php if($userIsAdmin === TRUE) { ?>

      <div class="block admin-menu">
        <h4>User Administration</h4>
        <ul>
            <li> ... </li>
            <li> ... </li>
        </ul>
      </div> 

  <?php } ?>

      <div class="block other-stuff">      
          <h4>Non-Admin Stuff</h4>
          <ul>
              <li> ... </li>
              <li> ... </li>
          </ul>
       </div>

  <?php $this->placeholder('sidebar')->captureEnd() ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜