4

How to display wishlist link (with functionality) in custom phtml file using template file in magento 2

12

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>

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.