1

I want to generate the header and serve it via API for displaying outside of the Magento website.

I've found a working example for Magento 1 but I couldn't figure out how to do it for Magento 2.

/*
         * Add specific layout handles to our layout and then load them.
         */
        $layout = Mage::app()->getLayout();
        $layout->getUpdate()
            ->addHandle('default')
            ->addHandle('ixcbadv_header')
            ->addHandle('facebook');

        if ($magento_logged_in) {
            $layout->getUpdate()->addHandle('customer_logged_in');
        } else {
            $layout->getUpdate()->addHandle('customer_logged_out');
        }

        $magento_google_analytics = $layout->createBlock('googleanalytics/ga')->setTemplate('googleanalytics/ga.phtml')->toHtml();

        $layout->getUpdate()->load();

        /*
         * Generate blocks, but XML from previously loaded layout handles must be
         * loaded first.
         */
        $layout->generateXml()->generateBlocks();

Any ideas? Thanks!

0

Your Answer

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

Browse other questions tagged or ask your own question.