magento getChildHtml和getBlockHtml有什么区别

getBlockHtml('block_name_here')block_name_here如果它在布局中找到它,那就得到你带有名字的块的html 。只有当该块是当前块的子
getChildHtml('block_name_here')块时,block_name_here才能获得具有名称的块的html 。

这是一个例子。考虑下一个布局部分

<block type="core/template" template="some_template.phtml" name="some_name" />
<block type="core/template" template="some_other_template.phtml" name="some_other_name" />

现在在模板文件中,some_template.phtml如果添加这行代码,<?php echo $this->getBlockHtml('some_other_name')?>您将获得该块的html some_other_name
如果添加,<?php echo $this->getChildHtml('some_other_name')?>你什么也得不到。

在以下场景中

<block type="core/template" template="some_template.phtml" name="some_name">
    <block type="core/template" template="some_other_template.phtml" name="some_other_name" />
</block>

getChildHtmlgetBlockHtml会得到同样的东西。块的html some_other_name

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论