【问题标题】:How to get Block children in Magento?如何在 Magento 中获取 Block 孩子?
【发布时间】:2012-06-07 11:13:27
【问题描述】:

我在 phtml 文件中,如何获取当前模板中的子块列表?

【问题讨论】:

    标签: magento


    【解决方案1】:
    $children = $this->getChild();
    

    检查app/code/Mage/Core/Block/Abstract.php中的代码

    public function getChild($name = '')
    {
        if ($name === '') {
            return $this->_children;
        } elseif (isset($this->_children[$name])) {
            return $this->_children[$name];
        }
        return false;
    }
    

    所以如果没有给出名字,它只会返回所有的孩子。

    【讨论】:

    • 我们也可以使用 $this->getChildHtml() 吗?里面有块名吗?
    • @RIK:$this->getChildHtml() 将返回所有子块的所有 html 内容。
    • @skafandri:在我的布局 xml 文件中,我添加了一个子 cms/block。然后我是我的父 phtml 文件,我写了$_block = $this->getChild('block_id'); 然后$_block->getTitle() 然后它不显示标题......$_block->getContent() 也不返回 html 内容。如果我尝试print_r($_block) 页面脚本就会死掉。如何在 phtml 中获取我的 cms 块的标题?
    • @MohammadFaisal 我也有同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2018-03-12
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2013-09-27
    • 1970-01-01
    相关资源
    最近更新 更多