Magento calls a block with getChildHtml

Please follow the code below, which is taken from my Magento Commerce theme:

extract from 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> 

extract from template / directory / 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> 

Basically, what I'm trying to do is create two blocks in a topMenu block and then print them in a template using the getChildHtml function.

Unfortunately, my function call fails, and two blocks load up to my top.phtml content.

Please give me some tips on what I am doing wrong.

Thank you very much in advance.

+4
source share
2 answers

Try the call function in the following file template/page/html/topmenu.phtml

0
source

I have made some progress.

After reading: Magento is a display block, but is only shown when I call it with getChildHtml

and: General information about the Magento block and block

I realized that core / text_list automatically prints the content, so I changed it to "page / html_wrapper".

The problem is that now the contents of these two elements are duplicated. Once before the contents of top.phtml, and the second when calling getChildHtml.

Any ideas would be highly appreciated.

0
source

Source: https://habr.com/ru/post/1481243/


All Articles