1

I would like to add login block only if customer are not logged in. So in my cms.xml page i change this code

<reference name="content">
        <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
        <block type="page/html_wrapper" name="cms.wrapper" translate="label">
            <label>CMS Content Wrapper</label>
            <action method="setElementClass"><value>std</value></action>
            <block type="cms/page" name="cms_page"/>
        </block>
    </reference>

this is my code

<?xml version="1.0"?>

<default>
    <reference name="footer">
        <block type="cms/block" name="cms_footer_links" before="footer_links">
            <!--
                The content of this block is taken from the database by its block_id.
                You can manage it in admin CMS -> Static Blocks
            -->
            <action method="setBlockId"><block_id>footer_links_company</block_id></action>
        </block>
        <block type="cms/block" name="cms_footer_links_sm" after="footer_links2">
            <!--
                The content of this block is taken from the database by its block_id.
                You can manage it in admin CMS -> Static Blocks
            -->
            <action method="setBlockId"><block_id>footer_links_sm</block_id></action>
        </block>
    </reference>
</default>

<cms_menu>
    <reference name="left_first">
        <block type="cms/block" name="cms_menu" >
            <action method="setBlockId"><block_id>cms_menu</block_id></action>
        </block>
    </reference>
</cms_menu>

<cms_page translate="label">
    <label>CMS Pages (All)</label>
    <remove name="left.permanent.callout"/>

    <update handle="cms_menu"/>

   <reference name="content">
    <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
    <block type="page/html_wrapper" name="cms.wrapper" translate="label">
        <label>CMS Content Wrapper</label>
        <action method="setElementClass"><value>std</value></action>
        <block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
        <block type="cms/page" name="cms_page"/>
    </block>
</reference>
    <customer_logged_in>
        <reference name="content">
                <remove  name="customer_form_login" />
        </reference>
    </customer_logged_in>



</cms_page>

<cms_index_index translate="label">
    <label>CMS Home Page</label>
</cms_index_index>

<cms_index_defaultindex>
    <remove name="right"/>
    <remove name="left"/>

    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="core/template" name="default_home_page" template="cms/default/home.phtml"/>
    </reference>
</cms_index_defaultindex>

<cms_index_noroute translate="label">
    <label>CMS No-Route Page</label>
</cms_index_noroute>

<cms_index_defaultnoroute>
    <remove name="right"/>
    <remove name="left"/>

    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="core/template" name="default_no_route" template="cms/default/no-route.phtml"/>
    </reference>
</cms_index_defaultnoroute>

In my logic this means that if the customer is logged in the login form will be removed but actually it will remove in every case. What is wrong?

  • when your checking the code are you logged in?? The code seems to look fine. – rob3000 Oct 27 '15 at 11:59
  • can you post your entire xml file? – Akhilesh Patel Oct 27 '15 at 12:01
  • I post my entire xml file – laura Oct 27 '15 at 13:20
2

I assume your xml code is invalid, you added your customer_logged_in inside your cms_page reference

It should be outside of cms_page try like below:

<cms_page translate="label">
    <label>CMS Pages (All)</label>
    <reference name="content">
        <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
        <block type="page/html_wrapper" name="cms.wrapper" translate="label">
            <label>CMS Content Wrapper</label>
            <action method="setElementClass"><value>std</value></action>
            <block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
            <block type="cms/page" name="cms_page"/>
        </block>
    </reference>
</cms_page>


<customer_logged_in>
    <reference name="content">
        <remove  name="customer_form_login" />
    </reference>
</customer_logged_in>

Or you can find customer_logged_in in customer.xml layout file and add remove block code in that file.

  • Both methods you have suggested are working fine!! Thank you very much!! – laura Oct 27 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.