Magento 使用 getChildHtml 调用 block

标签 magento layout block

请遵循以下代码,该代码取自我的 Magento Commerce 主题:

从 layout/page.xml 中提取

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
    <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
    <block type="directory/currency" name="store_currency_selector" as="store_currency_selector" template="directory/currency_top.phtml"/>
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
        <label>Navigation Bar</label>
        <block type="page/template_links" name="top.links.mobile" as="topLinksMobile"/>
        <block type="checkout/cart_sidebar" name="cart_sidebar_mobile" as="cartSidebarMobile" template="checkout/cart/topbar.phtml"/>
    </block>
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
        <label>Page Header</label>
        <action method="setElementClass"><value>top-container</value></action>
    </block>
    <block type="checkout/cart_sidebar" name="cart_sidebar" as="topcart" template="checkout/cart/topbar.phtml"/>
</block>

从模板/目录/导航/top.phtml 中提取
<li class="level0 nav-2 active level-top first parent">
    <a href="javascript:;">ACCOUNT</a>
    <?php echo $this->getParentBlock()->getChildHtml('topLinksMobile'); ?>
</li>
<li class="level0 nav-3 active level-top first parent">
    <a href="javascript:;">CART</a>
    <?php echo $this->getChildHtml('cartSidebarMobile'); ?>
</li>

基本上,我想要做的是在“topMenu”块内创建两个子块,然后使用“getChildHtml”函数将它们打印到模板中。

不幸的是,我的函数调用失败了,而这两个块是在我的 top.phtml 生成内容之前加载的。

请给我一些关于我做错了什么的建议。

提前谢谢了。

最佳答案

我进步了一点。

通过阅读:Magento - display block but only show when I call it with getChildHtml

和:Understanding Magento Block and Block Type

我明白 核心/文本列表自动打印内容,所以我将类型更改为“page/html_wrapper”。

问题是现在这两个元素的内容是重复的。一次在 top.phtml 的内容之前,第二次在调用 getChildHtml 时。

任何想法将不胜感激。

关于Magento 使用 getChildHtml 调用 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16595123/

相关文章:

c++ - 根据 std::sort() 实现 qsort()

magento - 无法修改 Magento 事件观察者中的响应,即使观察者正在触发

magento - Magento 的空白主题是否仍应用作主题基线(Magento 1.7 版)?

php - Magento 在下载链接中添加逗号

html - 包含数据网格的响应式网页布局

java - 当 javafx 中发生操作时,如何更改分割 Pane 的一半,同时保持另一半不变

hash - 这是Perl 6哈希还是 block ?

magento - 从 CSV 导入 magento 中另一个产品的追加销售产品

java - Android - 动态微调器

c++ - 用 C++ lambda 模仿 Obj-C block 行为