我像这样初始化我的占位符:
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来展示。
如何替换/覆盖占位符视图脚本中的内容?
答案 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'); ?>