1

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?

Community
  • 1
  • 1
pasine
  • 11,311
  • 10
  • 49
  • 81

1 Answers1

0

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.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • you are right: adding the logged status in my handles, I get the right layout! But I have some problem to retrieve this information! I have update my question with new code: can you help me? – pasine Jul 20 '11 at 22:53
  • Use login goes beyond just the layout system. You may be loading the right blocks, but because the state of your user in the system is actually NOT logged in, you get the not logged in stuff. – Alana Storm Jul 20 '11 at 23:15
  • My user is actually logged in, but I still can't see anything changing! – pasine Jul 21 '11 at 09:13