Login Check für CMS-Seiten Magento

 

How can CMS pages be designed differently depending on whether a user is logged in or not? Basically, it's relatively simple: You create a PHTML file and then include it in the CMS page. In this file, you can use the isLoggedIn function, which returns whether the user is logged in or not, allowing you to generate different outputs, such as calling different static blocks.

 

 

An example approach: You can create the PHTML file, for example, as 

 

\app\design\frontend\econcess\default\template\page\html\service_sidebar.phtml

 

with the following content (here, also distinguishing between store views / languages):

 

 

$store_code = Mage::app()->getStore()->getCode();

if ($store_code == 'de') {

                if (Mage::getSingleton('customer/session')->isLoggedIn()) {

                               echo $this->getLayout()->createBlock('cms/block')->setBlockId('service_submenu')->toHtml();

                } else {

                               echo $this->getLayout()->createBlock('cms/block')->setBlockId('service_submenu_logged_out')->toHtml();

                }

} else {

                if (Mage::getSingleton('customer/session')->isLoggedIn()) {

                               echo $this->getLayout()->createBlock('cms/block')->setBlockId('service_submenu_eng')->toHtml();

                } else {

                               echo $this->getLayout()->createBlock('cms/block')->setBlockId('service_submenu_eng_logged_out')->toHtml();

                }             

}

 

 

We can now include different static blocks depending on the language and login status (service_submenu, service_submenu_logged_out, service_submenu_eng, service_submenu_eng_logged_out).

 

We now include the service_sidebar.phtml file in the layout update of the desired page using

 

 

<reference name="left_first">

               <block type="core/template" name="service_sidebar" template="page/html/service_sidebar.phtml"/>

</reference>

 

 

That's it! Tested with Magento CE 1.9.1.0.