I was wondering how Magento merge
I was expecting something like
1 2 3 4 | < default > < update handle = "customer_logged_in" if = "logged_in" /> < update handle = "customer_logged_out" if = "logged_out" /> </ default > |
Obviously, there is not such codes in layouts.
I searched within Magento folder for keyword “customer_logged_in”, but only occurrences I could find in layout/customer.xml.
So, how is customer_logged_in/out handle added to Magento layout?
At last, I found
1 2 3 4 5 6 7 8 9 10 | class Mage_Customer_Model_Observer { public function beforeLoadLayout( $observer ) { $loggedIn = Mage::getSingleton( 'customer/session' )->isLoggedIn(); $observer ->getEvent()->getLayout()->getUpdate() ->addHandle( 'customer_logged_' .( $loggedIn ? 'in' : 'out' )); } } |
by tracing addHandle() in app/core/Mage/Core/Model/Layout/Update.php.
I must say using observer adding layout handle makes very easy for other modules to detect customer login status.
Leave a Reply