请遵循以下代码,该代码取自我的 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 生成内容之前加载的。
请给我一些关于我做错了什么的建议。
提前谢谢了。