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 Hintroozzak– roozzak2016-06-14 09:07:26 +00:00Commented Jun 14, 2016 at 9:07
Add a comment
|
2 Answers
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(); ?>
-
It worked for me . Voted up response.Jarnail S– Jarnail S2016-11-29 09:17:36 +00:00Commented Nov 29, 2016 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 helpJoey– Joey2017-10-18 12:04:57 +00:00Commented Oct 18, 2017 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– Chintan Kaneriya2019-01-10 07:15:18 +00:00Commented Jan 10, 2019 at 7:15
Yes. Adding
<?php echo $this->getLayout()
->createBlock('Magento\Checkout\Block\Cart\Sidebar')
->setTemplate('Magento_Checkout::cart/minicart.phtml')
->toHtml(); ?>
to header.phtml works
-
thanks man... can you please tell me how can we add block from another modules..??kalpak savaliya– kalpak savaliya2016-06-25 09:06:49 +00:00Commented Jun 25, 2016 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.Jarnail S– Jarnail S2016-11-29 09:43:39 +00:00Commented Nov 29, 2016 at 9:43