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 pre-loading
phtml file using following code :
<div id="modal-form" >
<?php include ($block->getTemplateFile('XYZ_module::view.phtml')) ?>
</div>
<script>
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function(
$,
modal
) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
title: 'Some Title',
buttons: [{
text: $.mage.__('Continue'),
class: '',
click: function () {
this.closeModal();
}
}]
};
var popup = modal(options, $('#modal-form'));
}
);
</script>
And then I'm opening this modal using following code :
$(".someBtn").click(function(event){
event.preventDefault();
$('#modal-form').modal('openModal');
});
Right now everything is working from loading in 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 pre-loading in 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?