I want to include the header and footer of magento outside of it.I have CORE_PHP with some jquery functionality and php function,In that Files,I need to add default Header/Footer of magento into that core_php files.How is it possible? I used this code for called magento functionality.

 * @author      MagePsycho <[email protected]>
 * @website     http://www.magepsycho.com
 * @category    using Header / Footer outside of Magento
$mageFilename = 'app/Mage.php';
echo $mageFilename;
require_once $mageFilename;
#ini_set('display_errors', 1);
Mage::getSingleton('core/session', array('name'=>'frontend'));

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

$headBlock          = $block->createBlock('page/html_head');// this wont give you the css/js inclusion
// add js
# add css

$headerBlock        = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();

$footerBlock        = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php echo $headBlock->toHtml(); ?>
<div class="wrapper">
    <div class="page">
        <?php echo $headerBlock; ?>
        <div class="main-container col1-layout">
            <div class="main">
                <div class="col-main">
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sit amet est lectus. Proin rhoncus faucibus mauris sit amet dictum. Donec auctor risus sed quam facilisis feugiat auctor augue mattis. Donec vitae ligula ac ligula scelerisque venenatis. Vestibulum vehicula sem nec justo aliquam lobortis. Vivamus malesuada lorem et diam consequat suscipit. Curabitur dui ante, semper eget imperdiet eu, elementum et leo. Duis id vestibulum lorem. Phasellus pulvinar condimentum urna et egestas. Sed eu orci turpis, sed facilisis lorem. Maecenas vel bibendum tortor. In congue, neque in placerat laoreet, sem lectus sagittis lorem, in pulvinar felis nibh a lorem. Proin viverra libero eu felis feugiat et porttitor enim aliquam. Cras a varius purus.</p>
Integer accumsan ligula sed lorem vehicula vitae rhoncus dolor ullamcorper. Curabitur vestibulum diam ac diam tincidunt quis adipiscing nisi placerat. Ut convallis consequat quam id imperdiet. Morbi ac risus sem. Curabitur egestas neque hendrerit felis sollicitudin ut vehicula enim mollis. Suspendisse sed leo nec risus scelerisque porttitor sed eget urna. Fusce id erat leo.</p>
        <?php echo $footerBlock; ?>

Here Above code will not working fine.my custom page located in [MAGENTO SITE]/tool/index.php.When i executed that file it results 404 redirect errors.How to render header/footer exactly into my custom page.Is it proper way for render header/footer into external file. Can please guide me..

1 Answer 1


vivek,you need set current store and current area and genaret Layout:

$mageFilename = 'app/Mage.php';
echo $mageFilename;
require_once $mageFilename;
#ini_set('display_errors', 1);

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

//load default xml layout handle and generate blocks

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

reset of your code
  • ..I put your code for individual custom page.it result blank page.I dont have no idea to implement how to set header and footer section in my custom page.any other idea for this..
    Feb 11, 2015 at 9:50
  • Here i create external page in default package, But i need to get current store and current layout ? Kindly advise me..How to get current layout
    Feb 11, 2015 at 10:31
  • wait vivek,i will see shorty
    – Amit Bera
    Feb 11, 2015 at 10:36
  • 1
    Here found that Mage::app("default"); this return only default css and js but i have theme package so how to call that theme css and js?
    Feb 11, 2015 at 10:39

Your Answer

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

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