1
votes

I used snippet suggested here

Load block outside Magento, and apply current template

to display a block outside Magento.
Here is my code:

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

$layout = Mage::app()->getLayout();
$layout->getUpdate()
    ->addHandle('default')
    ->load();

$layout->generateXml()
       ->generateBlocks();

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

The header is printed, but the topLinks are different from those displayed in Magento.
Even more, the html is slightly different (some divs are missing).
This is my XML layout:

<block type="page/html_header" name="header" as="header">
    <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
        <label>Navigation Bar</label>
    </block>
    <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
    <block type="page/template_links" name="top.links" as="topLinks"/>
    <block type="page/html_wrapper" name="top.bar" as="topBar" translate="label">
        <label>Breadcrumbs</label>
        <action method="setElementClass"><value>top-bar</value></action>
        <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
    </block>
    <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
        <label>Page Header</label>
        <action method="setElementClass"><value>top-container</value></action>
    </block>
</block>

What's wrong?

UPDATE

Thanks to Alan Storm's suggestion, now I know the error is not setting correct handles.
I need to add customer_logged_in or customer_logged_out to $layout.
I've tried with

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

$login_status = '';
if($session->isLoggedIn()){
    $login_status = 'customer_logged_in';
} else {
    $login_status = 'customer_logged_out';
} 

But my user results always logged out even when it's logged in.
What am I missing?

1

1 Answers

0
votes

For starters, you've only loaded a single layout handle. Besides the default handle, every Magento page request loads a handle for the store (such as STORE_english ) and a handle indicating if the customer is logged in or out (such as customer_logged_out). Without these handles, certain things don't happen, and the final rendered page is going to look different.