Magento用getChildHtml调用一个块

Dra*_*jan 5 layout block magento

请遵循以下代码,该代码来自我的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>
Run Code Online (Sandbox Code Playgroud)

从template / catalog / navigation / 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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

提前谢谢了。

Dee*_*lah 0

尝试以下文件中的调用函数 template/page/html/topmenu.phtml