1

I want to hide my CMS block if customer is logged in. This is how my block is added to OPC page via local.xml file.

<opc_index_index>
    <reference name="content">
        <block type="cms/block" name="cart_sinup" before="_">
            <action method="setBlockId">
                <block_id>signup</block_id>
            </action>
        </block>
    </reference>
</opc_index_index>

Note: I cannot use <customer_logged_in> because I want this only in opc_index_index page.

1

You can do this simply by using a css.

when you create a CMS Block assign a class or id to its container like <div class="customer_login_condition"> and on app\design\frontend\<YOUR_PACKAGE>\<YOUR_THEME>\template\page\html\footer.phtml add the css like following at the bottom of phtml.

<?php
if(Mage::getSingleton('customer/session')->isLoggedIn()){
?>
    <style>
        .customer_login_condition {display:none;}
    </style>
<?php
}
?>

Hope this helps you.

|improve this answer|||||
  • Thanks @ashish Yes this would work but it is not the right solution since the whole block will rendered in every case and then displayed as none. – saiid Jun 2 '16 at 5:27
  • yes i am also looking for a perfect solution of this.i would love to here from some one expert for this. – Ashish Madankar M2 Professiona Jun 2 '16 at 5:30
1

I have solved this problem by replacing the following xml

<opc_index_index>
    <reference name="content">
        <block type="cms/block" name="cart_sinup" before="_">
            <action method="setBlockId">
                <block_id>signup</block_id>
            </action>
        </block>
    </reference>
</opc_index_index>

with

<opc_index_index>
    <reference name="content">
        <block type="core/template" name="cart_sinup" before="_" template="ds/regaddress/opc_signup_wrapper.phtml" />
    </reference>
</opc_index_index>

in my local.xml and then create a new template file

app/design/frontend/package/theme/template/ds/regaddress/opc_signup_wrapper.phtml

and add this code in it.

<?php 
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){  
        echo $this->getLayout()->createBlock('cms/block')->setBlockId('signup')->toHtml(); 
    }
?>

What I'm doing here is rendering my cms_block in template file with the user logged in check and then adding this block via xml.

Cheers :)

|improve this answer|||||
0

In success.phtml you could do:

if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
    echo $this->getChildHtml('cart_sinup');
}

Typo in "sinup", but I just matched yours.

This will output the block if customer is not signed in, if they are signed in it will simply continue.

|improve this answer|||||
  • CMS static blocks are not rendered by using getCHildHtml function! – saiid Jun 1 '16 at 4:21
  • @MuhammadSaiid actually they are, since you define a new block within content called "cart_sinup" containing the content of "cms static block signup" and you can simply call it by its name property, in this case "cart_sinup". Or you could add the "as" property and call it by that name instead. – Vindfrisk Jun 1 '16 at 12:37
  • I didn't have to getChildHtml( ) my block and it is still rendered on my opc_index_index page with only the layout xml I have written above. – saiid Jun 2 '16 at 5:31
  • @MuhammadSaiid yes that is actually true, since "content" is of "core/text_list", what other blocks do you have in handle "opc_index_index", maybe you could target that and use the if statement inside that block. EDIT: ok saw you found I solution – Vindfrisk Jun 2 '16 at 18:32

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.