What is the easiest/most recommended way to have some conditional layout logic based on if a user is logged or not?
eg.. in pseudocode
if (customer logged in)
display this custom onepage checkout layout block
otherwise
display this other custom layout block (for guests)
Use conditions in your xml file (local.xml, page.xml, etc.). E.g. to add a cms block if customer is logged in:
<customer_logged_in>
<reference name="name_of_reference_block">
<block type="cms/block" name="block_name">
<action method="setBlockId">
<block_id>block_id</block_id>
</action>
</block>
</reference>
</customer_logged_in>
And same logic for logged out customers, e.g. remove a block:
<customer_logged_out>
<reference name="name_of_reference_block">
<remove name="name_of_block_to_remove"></remove>
</reference>
</customer_logged_out>
You can also use Magento customer helper in your template:
if($this->helper('customer')->isLoggedIn()){
//Show block to logged in customers
}else{
// Show different block to guest users
}
Alternatively use:
Mage::helper('customer')->isLoggedIn()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With