2

i have created block in theme in magento2. block location is "theme-folder/template/html/header.phtml".
i want to add minicart in this Phtml file.

  • you can extend by refferenceBlock of "minicart", check with Template Path Hint – roozzak Jun 14 '16 at 9:07
7

Not Tried but you can add directly in phtml with below code

<?php  echo $this->getLayout()
          ->createBlock('Magento\Checkout\Block\Cart\Sidebar')
          ->setTemplate('Magento_Checkout::cart/minicart.phtml')
          ->toHtml(); ?>
| improve this answer | |
  • It worked for me . Voted up response. – Jai Nov 29 '16 at 9:17
  • @Qaisar Satti I need to add form.mini.phtml from search module. how can I do it? I have seperate header for mobile view and I need to display minicart when I click on icon I put as cart(custom inage as icon). please help – Joey Oct 18 '17 at 12:04
  • @Qaisar Satti I added your code in header but it seems that content is not rendering properly in minicart popup so do you have any solution for this? – Chintan Kaneriya Jan 10 '19 at 7:15
3

Yes. Adding

<?php  echo $this->getLayout()
          ->createBlock('Magento\Checkout\Block\Cart\Sidebar')
          ->setTemplate('Magento_Checkout::cart/minicart.phtml')
          ->toHtml(); ?>

to header.phtml works

| improve this answer | |
  • thanks man... can you please tell me how can we add block from another modules..?? – kalpak savaliya Jun 25 '16 at 9:06
  • I hope you already done this but want to update community that above code can be added in any custom phtml file and minicart will display there. – Jai Nov 29 '16 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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