Magento:引用自定义块无效
我试图引用其他自定义模块中的一个块,以通过布局文件添加子块,但它不起作用 第一个布局文件包含Magento:引用自定义块无效,magento,layout,module,Magento,Layout,Module,我试图引用其他自定义模块中的一个块,以通过布局文件添加子块,但它不起作用 第一个布局文件包含 <catalog_product_view> <reference name="content"> <block type="core/template" name="tabcontainer" as="tabcontainer" template="store/tabcontainer.phtml" >
<catalog_product_view>
<reference name="content">
<block type="core/template" name="tabcontainer" as="tabcontainer"
template="store/tabcontainer.phtml" >
<block type="catalog/product_list_related" name="kitparts"
template="store/product/kitparts.phtml"/>
</block>
</reference>
</catalog_product_view>
但是productshippinginfo
块肯定包含在布局中时不会显示(使用Alan Storm的layoutviewer插件)。如果我引用内容
,则会显示
怎么了?难道不能从自定义扩展向自定义块添加子块吗
谢谢你的帮助
(我正在使用Magento 1.6.1.0)
[编辑]
在tabcontainer.phtml中,我正在呼叫
您很接近了。您只需将其添加到store/tabcontainer.phtml
文件:
getChildHtml('productshippinginfo');?>
作为“内容”子级的块在不更改模板的情况下呈现的原因是“内容”块是一个核心/text\u列表
块。如果查看Mage\u Core\u Block\u Text\u列表
,您将看到在其呈现方法(\u toHtml()
)中,它呈现其子对象
您还可以将空的getChildHtml()
调用添加到tabcontainer
模板中,以实现与core/text\u列表
类似的效果-事实上,如果您使用getChildHtml(“”,false,true)
您将获得已排序的子项(设置为before=“”
和after=“”
参数)
编辑:根据OP的注释调整了getChildHtml()调用语法。正确的发现是,第一个参数必须是空字符串a/o/t a布尔值。在第二个布局中,我认为您需要提供嵌套:
<catalog_product_view>
<reference name="content">
<reference name="tabcontainer">
<block type="productshippinginfo/productshipping" name="productshippinginfo"
template="productshippinginfo/productshipping.phtml" after="kitparts"/>
</reference>
</reference>
</catalog_product_view>
为了让maganto把它捡起来
因为你在做什么
<?php echo $this->getChildHtml(); ?>
除非您希望它出现在HTML输出中的特定位置,否则不需要具体地按名称调用它
为了测试块是否出现在页面中,请在块标记中添加output=“toHtml”
<block type="productshippinginfo/productshipping" name="productshippinginfo"
template="productshippinginfo/productshipping.phtml" after="kitparts" output="toHtml"/>
首先:谢谢
添加一个依赖项来控制我的插件的加载顺序它可以工作
文件中:app/etc/modules/Company_ContentModule.xml
<Company_ContentModule>
<active>true</active>
<codePool>local</codePool>
<depends>
<Company_ContainerModule />
</depends>
</Company_ContentModule>
真的
地方的
因此,内容模块在容器模块之后加载。我不想添加getChildHtml(“productshippinginfo”),因为tabcontainer应该接受(将来)放置在其中的任何块。但是我很困惑,调用getChildHtml(false,false,true)不会产生任何输出。调用getChildHtml(“”,false,true)的结果与调用getChildHtml()的结果相同。当我调用getChild()时,我只得到kitparts块,你是对的。出于某种原因,对第一个参数有严格的检查,它必须是一个空字符串才能按照aI的建议工作。如果需要tabcontainer模板无需修改即可回显其子项,则应使用
或
;如果希望使用排序语法(之前和之后),请使用前一种语法。如果不进行调试,则无法确定,但必须确保在加载定义所引用块的布局文件的模块之后加载模块。另一个因素是布局更新句柄的处理顺序,即您不能引用中的块。您可以通过使模块依赖于在app/etc/modules/*.xml文件中声明tabcontainer块的模块来影响加载顺序。是的,当我添加output=“toHtml”时,该块会出现,但不幸的是,嵌套引用不起作用:(
<Company_ContentModule>
<active>true</active>
<codePool>local</codePool>
<depends>
<Company_ContainerModule />
</depends>
</Company_ContentModule>