ここで提案されたスニペットを使用しました
Magento の外部でブロックを読み込み、現在のテンプレートを適用する
Magento 外のブロックを表示します。
これが私のコードです:
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;
ヘッダーは印刷されますが、topLinks は Magento に表示されるものとは異なります。
さらに、html が少し異なります (一部の div が欠落しています)。
これは私のXMLレイアウトです:
<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>
どうしたの?
アップデート
Alan Storm の提案のおかげで、エラーが正しいハンドルを設定していないことがわかりました。
$layout に customer_logged_in または customer_logged_out を追加する必要があります。
私は試してみました
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';
}
しかし、ユーザーの結果は、ログインしていても常にログアウトされます。
何が欠けていますか?