0

I'm trying to add a login box only in home page. Of course, it should disappear when a customer is logged in. So I put this layout update in the home page, but it doesn't work:

<customer_logged_out>
    <reference name="header">
        <block type="customer/form_login" name="header_customer_form_mini_login" template="customer/form/toplink-login-custom.phtml"/>
    </reference>
</customer_logged_out>

It works only:

 <reference name="header">
     <block type="customer/form_login" name="header_customer_form_mini_login" template="customer/form/toplink-login-custom.phtml"/>
  </reference>

But, of course, the box is shown when the customer is logged too.

1
  • Put your code into the question..
    – Amit Bera
    Commented Oct 15, 2014 at 12:10

3 Answers 3

1

Use the case in which it works:

<reference name="header">
    <block type="customer/form_login" name="header_customer_form_mini_login" template="customer/form/toplink-login-custom.phtml"/>
</reference>

and just edit the template customer/form/toplink-login-custom.phtml and wrap its contents in an if statement that checks if the customer is logged in or not.

<?php if (!Mage::getSingleton('customer/session')->isLoggedIn()) : ?>
    <!-- your template here -->
<?php endif;?>
3
  • worked thanks. In your opinion, why the first code does not work at all?
    – apedic
    Commented Oct 15, 2014 at 16:43
  • @AntonioPedicini. The first approach did not work because you cannot add layout handles in a cms page layout update field. You can only add or remove blocks. The layout handle used for the homepage is <cms_index_index>. What you add in the backend gets appended to this layout handle and you cannot have layout handles inside other layout handles.
    – Marius
    Commented Oct 15, 2014 at 20:13
  • thanks, shall I use an update handle in that case?
    – apedic
    Commented Oct 17, 2014 at 18:42
0

What I did was write a block with a login form then echo it in a hidden div if Mage::getSingleton('customer/session')->isLoggedIn() == false
And then I make it pop up using Flexslider.

0

Try to approach that another way. Let's add the block, but when customer is logged in – then remove it.

Go to your app/design/frontend/THEME/THEME/layout/customer.xml

Find section responsible for layouting page when customer is logged in and add remove attribute.

<customer_logged_in>
    <remove name="header_customer_form_mini_login"></remove>
</customer_logged_in>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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