If you want to include the header and footer of Magento outside of it, say for example for third-party cms/application then you can use the following trick.
Step 1: Using Magento Code outside of Magento
<?php
/**
* @author MagePsycho <[email protected]>
* @website https://www.magepsycho.com
* @category using Header / Footer outside of Magento
*/
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
Step 2: Getting Head Block
$block = Mage::getSingleton('core/layout');
# HEAD BLOCK
$headBlock = $block->createBlock('page/html_head');// this wont give you the css/js inclusion
// add js
$headBlock->addJs('prototype/prototype.js');
$headBlock->addJs('lib/ccard.js');
$headBlock->addJs('prototype/validation.js');
$headBlock->addJs('scriptaculous/builder.js');
$headBlock->addJs('scriptaculous/effects.js');
$headBlock->addJs('scriptaculous/dragdrop.js');
$headBlock->addJs('scriptaculous/controls.js');
$headBlock->addJs('scriptaculous/slider.js');
$headBlock->addJs('varien/js.js');
$headBlock->addJs('varien/form.js');
$headBlock->addJs('varien/menu.js');
$headBlock->addJs('mage/translate.js');
$headBlock->addJs('mage/cookies.js');
# add css
$headBlock->addCss('css/styles.css');
$headBlock->getCssJsHtml();
$headBlock->getIncludes();
Step 3: Getting Header Block
# HEADER BLOCK
$headerBlock = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();
Step 4: Getting Footer Block
# FOOTER BLOCK
$footerBlock = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml();
Putting it all together
<?php
/**
* @author MagePsycho <[email protected]>
* @website https://www.magepsycho.com
* @category using Header / Footer outside of Magento
*/
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$block = Mage::getSingleton('core/layout');
# HEAD BLOCK
$headBlock = $block->createBlock('page/html_head');// this wont give you the css/js inclusion
// add js
$headBlock->addJs('prototype/prototype.js');
$headBlock->addJs('lib/ccard.js');
$headBlock->addJs('prototype/validation.js');
$headBlock->addJs('scriptaculous/builder.js');
$headBlock->addJs('scriptaculous/effects.js');
$headBlock->addJs('scriptaculous/dragdrop.js');
$headBlock->addJs('scriptaculous/controls.js');
$headBlock->addJs('scriptaculous/slider.js');
$headBlock->addJs('varien/js.js');
$headBlock->addJs('varien/form.js');
$headBlock->addJs('varien/menu.js');
$headBlock->addJs('mage/translate.js');
$headBlock->addJs('mage/cookies.js');
# add css
$headBlock->addCss('css/styles.css');
$headBlock->getCssJsHtml();
$headBlock->getIncludes();
# HEADER BLOCK
$headerBlock = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();
# FOOTER BLOCK
$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">
<html>
<head>
<?php echo $headBlock->toHtml(); ?>
</head>
<body>
<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>
<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>
</div>
</div>
</div>
<?php echo $footerBlock; ?>
</div>
</div>
</body>
</html>
And you can see the output as depicted below:
Hope this article was helpful.
Yes? Then don’t forget to jot your valuable comments.
Happy E-Commerce!