Magento 1.9 Header and Footer – Using Magento Header and Footer Files Outside Magento in Simple PHP File

frontendmagento-1.9

I want to use magento header and footer files(custom theme) in my custom php file. How can I get header and footer. php file location is root folder.

I am using this code

require("app/Mage.php");
umask(0);
Mage::app();
ini_set('display_errors', 1);

Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton("customer/session");
$layout = Mage::getSingleton('core/layout');

$headerBlock = $layout->createBlock('page/html_header')->setTemplate('page/html/header.phtml');
$currencyBlock = $layout->createBlock('directory/currency')->setTemplate('currency/currency.phtml');
$headerBlock->setChild('currency_selector', $currencyBlock);
echo $headerBlock = $headerBlock->toHtml();

Best Answer

You need call design area Mage::app()->loadArea('frontend'); at your script.

<?php
include_once "app/Mage.php";
umask(0);
Mage::app()->loadArea('frontend');

$layout = Mage::getSingleton('core/layout');

//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();

//get the loaded head and header blocks and output
$headBlock = $layout->getBlock('head');
$headerBlock = $layout->getBlock('header');
echo $headBlock->toHtml() . $headerBlock->toHtml();

get footer

$footerBlock = $layout->getBlock('footer');
echo $footerBlock->toHtml();

I hope this will help you.

Related Topic