2

I want to add default wishlist sidebar section into my Magento_Theme template,

Layout xml file:

<referenceBlock name="header.panel">

            <block class="Magento\Framework\View\Element\Template" name="mylocation.block" template="Magento_Theme::location_link.phtml" after="-">

              <!-- Wishlist sidebar section -->
            <block class="Magento\Wishlist\Block\Customer\Sidebar" name="wishlist_sidebar" as="wishlist" template="Magento_Wishlist::sidebar.phtml"/> 

            </block>

        </referenceBlock>

FYI : The following code coming from core vendor\magento\module-wishlist\view\frontend\templates\sidebar.phtml

  <!-- Wishlist sidebar section -->
<block class="Magento\Wishlist\Block\Customer\Sidebar" name="wishlist_sidebar" as="wishlist" template="Magento_Wishlist::sidebar.phtml"/> 

After added in layout xml file and getting this block using getChildHtml in app\desigh\frontend\Zero\my_theme\Magento_Theme\templates\location_link.phtml

<?php echo $block->getChildHtml('wishlist');?>

Not working, any help thanks.

2 Answers 2

2

Your method is not working because your blocks are siblings and do not have a parent/child relationship. The key is the word child in getChildHtml.

If you nest your wishlist block inside the location block that will work.

Also, header.panel is a container, not a block. See https://github.com/magento/magento2/blob/5e57ddd6b0452121e26ce93c74029cf58c4b1d6b/app/code/Magento/Theme/view/frontend/layout/default.xml#L34

<referenceContainer name="header.panel">
        <block class="Magento\Framework\View\Element\Template" name="mylocation.block" template="Magento_Theme::location_link.phtml" after="-">
            <!-- Wishlist sidebar section -->
            <block class="Magento\Wishlist\Block\Customer\Sidebar" name="wishlist_sidebar" as="wishlistc" template="Magento_Wishlist::sidebar.phtml"/> 
        </block>
    </referenceContainer>
11
  • After i updated your code, still response not return to the phtml file, i am trying to get the wishlist sidebar section in my phtml file? Screenshot : snipboard.io/qgLr7a.jpg
    – zus
    Mar 25, 2021 at 14:38
  • In my phtml file i am using : <?php echo $block->getChildHtml('wishlistc');?>
    – zus
    Mar 25, 2021 at 14:39
  • That's correct. Is your location_link.phtml file rendering on the frontend?
    – Ben Crook
    Mar 25, 2021 at 15:23
  • Yes, but still wishlist sidebar not showing.
    – zus
    Mar 25, 2021 at 15:25
  • code: codeshare.io/5QxPpL
    – zus
    Mar 25, 2021 at 15:29
0

Try to move it instead:

   <move element="wishlist_sidebar" destination="mylocation.block" before="-"/>

Also make sure to clear the cache, sometimes not even when running flush and clear cache, magento stop using cached. When it happens I need to clear static files. I recommend disable full_page and block_html cache while you working on it:

bin/magento c:d full_page

bin/magento c:d block_html
1
  • FYI - I try to get that wishlist section inside the dropdown dialog widget bit.ly/3vZtpPe, i have icon on header if customer click that icon dropdown show the wishlist products, so that i am using <?php echo $block->getChildHtml('wishlist');?> inside the phtml file.
    – zus
    Mar 25, 2021 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.