【发布时间】:2013-04-08 14:49:30
【问题描述】:
我正在尝试重新组织我的右侧边栏。在模板(2columns-right)中,它调用:
<?php echo $this->getChildHtml('right') ?>
我在哪里可以找到这个变量的内容?
【问题讨论】:
标签: magento content-management-system e-commerce
我正在尝试重新组织我的右侧边栏。在模板(2columns-right)中,它调用:
<?php echo $this->getChildHtml('right') ?>
我在哪里可以找到这个变量的内容?
【问题讨论】:
标签: magento content-management-system e-commerce
对getChildHtml() 方法的调用会加载带有传递给该方法的名称的子块的 HTML,因此在这种情况下,我们正在寻找一个名为 right 的子块。 p>
要确定在哪里可以找到这个子块,我们需要知道哪个块正在调用这个方法。我知道对 getChildHtml() 方法的特定调用出现在主页列模板中,因为 right 是列之一。所以看一下page.xml布局文件,搜索找到方法调用的模板文件,你会发现这样的:
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
</reference>
在布局文件中使用<reference> 标签允许您更改目标块,<action> 标签允许您在正在使用的块内运行块方法。所以这部分布局将模板设置在 root 块内。由此我们知道是调用getChildHtml()方法的root块。
接下来让我们看看 root 块在布局中的定义位置,它在同一个 page.xml 布局文件中,应该就在顶部附近:
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
...
<block type="core/text_list" name="right" as="right" translate="label">
<label>Right Column</label>
</block>
...
</block>
在这个块中定义了很多,但是你可以看到它被命名为 root 并且定义了很多子块。这些子块之一被命名为 right,并且正是这个块的 HTML 由 getChildHtml() 方法输出。请务必注意块类型 - core/text_list。这是一种特殊的块类型,这意味着当使用getChildHtml() 方法渲染此块的 HTML 时,子块也将被渲染。如果块类型是 page/html 就像根块一样,添加到 right 块的每个子块都需要它自己的 getChildHtml() 方法调用,使用这种块类型,你只需要调用getChildHtml('right') 和所有子块也将被渲染。
如您所见,right 块在这里定义,但它是空的。这是因为与引用根块 (<reference name="root">) 的标记完全相同,其他布局文件通过引用 right 将子块添加到 right 块块。
<reference name="right">
...
</reference>
因此,要最终回答您的问题(并希望在此过程中提供一些信息),您需要在 page.xml 以外的布局文件中查找对 right 块的引用,在这里您将查找getChildHtml() 方法调用输出的所有子内容。
您可以更改添加到您自己的模块布局文件中的 right 块的内容,如果您不创建模块,则可以更改 local.xml 布局文件。我在回答 here 中简要介绍了 local.xml 布局文件,并使用示例语法添加新块和删除在其他布局文件中添加的块。
【讨论】:
你会在你的 layout.xml 文件中找到一切的来源。它会有列表块,调用 .phtml 文件和数据来自那里。我希望你明白我想要传达的意思。
【讨论】:
<reference name="right">
<block type="yourmodule/yourblock" name="yourblock" as="yourblock" />
</reference>
你可以像这样添加你的自定义块。
【讨论】:
<layout version="1.0"> <adminhtml_sales_order_shipment_view> <reference name="content"> <block type="paketid_booking/adminhtml_sales_order_shipment_view_booking" name="paketid_booking" template="paketid/booking.phtml" /> </reference> </adminhtml_sales_order_shipment_view> </layout>我的自定义块没有显示在发货视图中?我错过了什么?有关完整问题,请查看:stackoverflow.com/questions/39340112/…