I have a phtml file view.php and its block class View.php. I need to show that phtml on a modal on checkout page and to do that I'm preloading that phtml file using following command

<div id="modal-form" >
    <?php include ($block->getTemplateFile('XYZ_module::view.phtml')) ?>
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                title: 'Some Title',
                buttons: [{
                    text: $.mage.__('Continue'),
                    class: '',
                    click: function () {

            var popup = modal(options, $('#modal-form'));

And then I'm opening this modal using following code


Right now everything is working from loading the phtml file in the modal and opening that modal on a button click. What's not working is the functions of View.php block class. I think the issue is with the preloading of phtml file using include function and because of that the php functions are hitting the server once and not when I actually open the modal. Can I reload or just load that phtml file dynamically when the modal opens on a button click?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.