0

I have Following widget and its working in cms page but now I want it to display in phtml file

{{widget type="Magento\Catalog\Block\Widget\RecentlyViewed" uiComponent="widget_recently_viewed" page_size="10" show_attributes="name,image,price,learn_more" show_buttons="add_to_cart,add_to_compare,add_to_wishlist" template="product/widget/viewed/grid.phtml" type_name="Recently Viewed Products"}}
1

Try with below way.

$recViewBlock = $this->getLayout()->createBlock(\Magento\Catalog\Block\Widget\RecentlyViewed::class);
$recViewBlock->setTitle("Recently Viewed Products");
$recViewBlock->setProductsCount(10);
$recViewBlock->setTemplate("product/widget/viewed/grid.phtml");
$recViewBlock->setDisplayType("recently.view.products");
$recViewBlock->setShowAttribute(add_to_cart,add_to_compare,add_to_wishlist);

echo $recViewBlock->toHtml();

Note : Above code is not tested you have to check. For more detail click here

I hope it helps!

| improve this answer | |
  • thanks for your answer but is shows error – Harsh Jayswal Mar 20 '19 at 12:49
0

phtml file :-

<?php echo $this->getLayout()->createBlock("Magento\Catalog\Block\Widget\RecentlyViewed")->setDisplayType("widget_recently_viewed")->setProductsCount("5")->setTemplate("product/widget/viewed/grid.phtml")->toHtml(); ?>
| improve this answer | |
0

Try this :

echo $this->getLayout()->createBlock("Magento\Catalog\Block\Widget\RecentlyViewed")->setDisplayType("your_display_type")->toHtml();
| improve this answer | |

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.