0

所以我想在我的视图脚本中使用一个 jQuery 选项卡容器。我已经对其进行了测试,所以我知道我已经完成了一切工作。

<?php $this->tabContainer()->addPane('container-name', 'label', 'content goes here'); ?>
<?php echo $this->tabContainer('container-name'); ?>

但这是我要放入窗格的内容:

<?php if (count($this->resources->links) > 0): ?>
    <h3>Links</h3>
    <ul>
    <?php foreach ($this->resources->links as $link): ?>
        <li><?php echo $link->title; ?></li>
    <?php endforeach ?>
    </ul>
<?php endif; ?>

如何将 if/foreach 块放入 addPane 函数的内容参数中?

4

1 回答 1

2

也许你想要的是ob_start()ob_get_clean()对。

<?php
ob_start();
if (count($this->resources->links) > 0): ?>
    <h3>Links</h3>
    <ul>
    <?php foreach ($this->resources->links as $link): ?>
        <li><?php echo $link->title; ?></li>
    <?php endforeach ?>
    </ul>
<?php endif;
$things = ob_get_clean();
$this->tabContainer()->addPane('container-name', 'label', $things);
echo $this->tabContainer('container-name'); ?>
于 2009-12-14T07:56:43.733 回答