3

I want to show phtml file inside popup on click of a button but it shows by default open how to resolve it anyone has an idea ?? I want to open when I click on button

<div>
    <a href="#" id="click-me">Notify Me</a>
</div>

<div id="popup-mpdal">
                <?php include ($block->getTemplateFile(Vendor_Module::notifyoutofstcoks.phtml')) ?>
</div>

  <script>
require(
    [
        'jquery',
        'Magento_Ui/js/modal/modal'
    ],
  function(
        $,
        modal
    ) {
        var options = {
            type: 'popup',
            responsive: true,
            innerScroll: true,
            buttons: [{
                text: $.mage.__('Continue'),
                class: '',
                click: function () {
                    this.closeModal();
                }
            }]
        };

        var popup = modal(options, $('#popup-mpdal'));
        $("#click-me").on('click',function(){
            $("#popup-mpdal").modal("openModal");
        });

    }
);
</script>
1

1 Answer 1

1

Try using this code to call phtml within another phtml file

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Vendor_Module::notifyoutofstcoks.phtml")->toHtml(); ?>

To open modal on link click follow devdocs tutorial https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/widgets/widget_modal.html

4
  • but how to show popup on click of the link ?? using this its shows by default whole phtml file Commented Apr 22, 2019 at 6:10
  • Updated my answer. Follow devdocs tutoral to use modal in order to show dialog box on link click Commented Apr 22, 2019 at 6:12
  • thank you it's working fine Commented Apr 22, 2019 at 6:36
  • Please mark answer as correct, so that your post is set to resolved and it would be helpful for others in future Commented Apr 22, 2019 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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