从视图脚本替换zend占位符内容

时间:2012-05-19 22:29:23

标签: php zend-framework

我像这样初始化我的占位符:

default.phtml(布局文件)

<?php $this->placeholder('hero')->captureStart(); ?>
<div class="primary">
  <h1>Foo bar!</h1>
</div>
<?php $this->placeholder('hero')->captureEnd(); ?>
<?php echo $this->placeholder('hero'); ?>

index.phtml(查看脚本文件)

<?php $this->placeholder('hero')->captureStart(); ?>
<div class="primary">
  <h1>Bar Baz!</h1>
</div>
<?php $this->placeholder('hero')->captureEnd(); ?>
<?php echo $this->placeholder('hero'); ?>

输出: 在我的输出中,我最终得到了两个标题。我只想要Bar baz来展示。

Bar Baz!

Foo Bar!

如何替换/覆盖占位符视图脚本中的内容?

1 个答案:

答案 0 :(得分:1)

captureStart() (Check Example #13)的默认设置为append,尝试将其设置为set

<?php $this->placeholder('hero')->captureStart('SET'); ?>
<div class="primary">
  <h1>Bar Baz!</h1>
</div>
<?php $this->placeholder('hero')->captureEnd(); ?>
<?php echo $this->placeholder('hero'); ?>