5

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(); 

2 Answers 2

4

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.

8
  • I want to use also session here also like user login/cart item how can I do this. Commented Jan 2, 2016 at 10:38
  • I have added this line and my session also working. Mage::getSingleton('core/session', array('name'=>'frontend')); Commented Jan 2, 2016 at 10:54
  • hope my help works. Commented Jan 2, 2016 at 10:55
  • I am getting url issue with this. for wishlist and logout Getting Url: example.com/customfile.php/wishlist/?___SID=U but I want this url example.com/wishlist/?___SID=U How can i get this Commented Jan 2, 2016 at 11:07
  • please check updated answer for footer. Commented Jan 2, 2016 at 11:18
3

Pushpendra Singh ,As @denish says,You have missed to call design area as fronted Mage::app()->loadArea('frontend');

Also,You have call the layout then no need to create blocks ('page/html_header','directory/currency') again using page/html_header, etc if it is already called at your design area.Just need to loaded those blocks using getBlock('');

$headerBlock = $layout->getBlock('header'); 

etc.If want to add new add block which does not ,you frontend area section then use createBlock() AND setChild FOR ADD ON EXITING LAYOUT

see more code at https://magento.stackexchange.com/a/5080

4
  • i have call it out Mage::app()->loadArea('frontend');. don't get dummy credit. tell true to all one. this is not for reputation you want. i am giving answer to help not for reputation as you. Commented Jan 2, 2016 at 10:29
  • I have just put my point of view on basic of question. Commented Jan 2, 2016 at 10:48
  • Sorry, denish ,i was said the text As @denish says.. . frontend' for Pushpendra Singh not for you. sorry for if it heart you.I do not take u credit .. This credit goes to all for this answered.May be my English make wrong meaning at u.Also remember once thing my friend that i have wrote answered at Mse not for reputation and it my hobby to answer here and i love it.If your thought about me " this is not for reputation you want" Then it totally wrong and i have no reason for u at this case. Commented Jan 2, 2016 at 10:55
  • ok buddy.......!!! Commented Jan 2, 2016 at 10:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.