I need to load a .phtml content on a popup.

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

    <div id="popup-mpdal" style="display:none;">
        <h1> Hi I'm here.... </h1>

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Elem‌​ent\Template")->setT‌​emplate("Namespace_Customtab::new.phtml"‌​)->toHtml();?>


            ) {
                var options = {
                    type: 'popup',
                    responsive: true,
                    innerScroll: true,
                    title: 'popup mpdal title',
                    buttons: [{
                        text: $.mage.__('Continue'),
                        class: '',
                        click: function () {

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


This is my code. How to load another phtml content instead of that div ? Please help me In find a solution.

custom file path: app/code/Namespace/Customtab/view/frontend/templates/product/view/new.phtml

  • Whats the issue have you faced? I m here content is not display after click on button? – Rakesh Jesadiya May 31 '17 at 6:30
  • When i click on the Click me button, it displays a popup with the Hi i'm here content. But instead of that i need to display another phtml page content. for that what i need to do? – Rita Jose May 31 '17 at 6:34
  • Try this code : <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/test.phtml")->toHtml();?> – Amrit Pal Singh May 31 '17 at 6:39
  • which phtml template want to define in popup? – Rakesh Jesadiya May 31 '17 at 6:41
  • @RakeshJesadiya a custom phtml – Rita Jose May 31 '17 at 6:42

You can try with below code,

if your phtml file contains any Custom Block then replace Magento\Framework\View\Elem‌​ent\Template with your custom block path.

<div id="popup-mpdal" style="display:none;">
    <h1> Hi I'm here.... </h1>
    <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Elem‌​ent\Template")->setT‌​emplate("Namespace_Customtab::product/view/new.phtml"‌​)->toHtml();?>
| improve this answer | |
  • not have any block, so i pasted like this <div id="popup-mpdal" style="display:none;"> <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Elem‌​ent\Template")->setT‌​emplate("Namesapce_Customtab::new.phtml"‌​)->toHtml();?> </div> but it shows a syntax error : Parse error: syntax error, unexpected '‌​' (T_STRING), expecting ',' or ')' in /opt/lampp/htdocs/magento214/app/code/Namesapce/Customtab/view/frontend/templates/product/view/gallery.phtml on line 30 – Rita Jose May 31 '17 at 6:57
  • is your module name "Namesap‌​ce_Customtab:? – Rakesh Jesadiya May 31 '17 at 6:59
  • yes.. Anything wrong? – Rita Jose May 31 '17 at 7:01
  • i think it should be Namespace not Namsapce, right you typomistake – Rakesh Jesadiya May 31 '17 at 7:02
  • its a typomistake when i wrote here, in code the module name s correct – Rita Jose May 31 '17 at 7:04

Got the answer to load phtml file:

<div id="popup-mpdal" style="display:none;">
    <?php include ($block->getTemplateFile('Namespace_Customtab::image.phtml')) ?>

By this, we can popup the custom phtml page.

| improve this answer | |

try this.

  `<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Namespace_Module::name_of_phtml.phtml")->toHtml(); ?>`
| improve this answer | |

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.