2

我正在阅读有关基本占位符用法的手册,它有这个例子:

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>");
    }

    // ...
}

我想几乎完全做到这一点,但我想有条件地向重复div的 s 添加更多的类值,如果可能的话,在渲染时,当所有内容都在占位符中时。我特别想做的一件事是将“first”类添加到第一个元素,将“last”类添加到最后一个元素。我假设我必须扩展Zend_View_Helper_Placeholder类来完成这个。

4

1 回答 1

1

设置的字符串setSeparator()将用于内爆容器中的元素。要么将其设置为空字符串,要么只是省略调用setSeparator()并插入分隔 div 以及其他内容:

  <?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() ?>
于 2010-03-25T18:53:43.617 回答