How to display wishlist link (with functionality) in custom phtml file using template file in magento 2
1 Answer
You can try something like the following code:
<a href="#" data-post='<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) ?>' class="action towishlist" data-action="add-to-wishlist"><span>' .
__('Add to Wish List') . '</span></a>
Refer the below file and related block for more details
\vendor\magento\module-catalog\view\frontend\templates\product\listing.phtml
Make sure your custom module should use
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"wishlist": {
"component": "Magento_Wishlist/js/view/wishlist"
}
}
}
}
}
</script>
-
hi @Krishna, can you please update for Add to compare and send to an email as well please? Commented May 12, 2020 at 6:32