1

Get block in phtml file not working - Please help me !

When clicking on the button, it shows popup fancybox but does not show content in it.

My phtml

<div id="contact-popup">
<?php
echo $block->getLayout()->createBlock('Magento\Contact\Block\ContactForm')
    ->setTemplate("Magento_Contact::form.phtml")->toHtml();
?>

<script type="text/javascript">
    require([
        'jquery',
        'jquery/jquery.cookie',
        'Amasty_HidePrice/js/fancybox/jquery.fancybox.min'
    ], function ($) {

        $("#helpdesk-contact-button").fancybox({
            'padding': '0px',
            'autoScale': true,
            'transitionIn': 'fade',
            'transitionOut': 'fade',
            'type': 'inline',
            'href': '#contact-popup',
            'onComplete': function() {
                //$.cookie('newsletter_popup', 'shown');
            },
            'tpl': {
                closeBtn: '<a title="Close" class="fancybox-item fancybox-close fancybox-newsletter-close" href="javascript:;"></a>'
            },
            'helpers': {
                overlay: {
                    locked: false
                }
            }
        });

    });

closed as off-topic by Amit Bera May 3 at 4:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Amit Bera
If this question can be reworded to fit the rules in the help center, please edit the question.

0

Following this way..

<div id="contact-popup">
<?php
echo $block->getLayout()->createBlock('Magento\Contact\Block\ContactForm')
    ->setTemplate("Magento_Contact::form.phtml")->toHtml();
?>

to

<div id="contact-popup">
<?php
echo $this->getLayout()->createBlock('Magento\Contact\Block\ContactForm')
    ->setTemplate("Magento_Contact::form.phtml")->toHtml();
?>

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