1

This is my XML from layout:

<customer_account_index>
    <reference name="content">
        <block type="name_module/customer_account_welcome" name="customer_account_dashboard" before="-" template="name_module/customer/account/welcome.phtml"/>
    </reference>
</customer_account_index>
<customer_account_index>
    <update handle="customer_account_dashboard" />
    <reference name="content">
        <block type="cms/block" name="customer_account_dashboard_welcome" before="-">
            <action method="setBlockId"><block_id>succes-startkit</block_id></action>
        </block>
    </reference>
</customer_account_index>

This is the content of my template:

<?php if ($this->shouldDisplayWelcome()):?>
    <div class="welcome-msg">
        <?php echo $this->getChildHtml('customer_account_dashboard_welcome') ?>
    </div>
<?php endif;?>

and my function from my block:

public function shouldDisplayWelcome()
{
        $session = Mage::getSingleton('core/session');
        $welcome = $session->getShowWelcomeMessage();

        if ($welcome === true) { 
            $session->setShowWelcomeMessage(false);

            return true;
        }

        return false;
}

Depends on what my function returns I want to display my static block or not. What am I doing wrong from the layout?

Thanks

[UPDATE]

Right now this version of the XML doesn't work:

 <customer_account_index>
        <reference name="content">
            <block type="cms/block" name="customer_account_dashboard_welcome" before="-">
                <action method="setBlockId" helper="mynamespace_mymodule/customer/shouldDisplayWelcome">
                    <block_id>succes-startkit</block_id>
                </action>
            </block>
        </reference>
    </customer_account_index>

If i make a syntax error in my helper, I got the error message, but no matter what i return true or false in my function my static block is still displayed.

2 Answers 2

1

You can try this ... then your helper should return block id

<reference name="content">
    <block type="cms/block" name="customer_account_dashboard_welcome" before="-">
        <action method="setBlockId">
            <block_id helper="YOURMODULE/YOURHELPER/shouldDisplayWelcome"/>
        </action>
   </block>
</reference>
1
  • Thx , its working for me :) May 24, 2017 at 14:12
1

You can add the helper parameter, like that sample below, so add the return of your helper like what you want to return:

<reference name="content">
    <block type="cms/block" name="customer_account_dashboard_welcome" before="-">
        <action method="setBlockId">
            <block_id helper="YOURMODULE/YOURHELPER/shouldDisplayWelcome"/>
        </action>
   </block>
</reference>

Helper called Data.php

public function() {

        $session = Mage::getSingleton('core/session');
        $welcome = $session->getShowWelcomeMessage();

        if ($welcome === true) { 
            $session->setShowWelcomeMessage(false);

            return 'block_id';
        }

        return false;

}

References:

Conditionally show/hide blocks in layout XML

https://stackoverflow.com/questions/5596193/magento-xml-layouts-specify-value-for-ifconfig

6
  • I moved my function from my block to my helper called Customer.php, like: <action method="setBlockId" ifconfig="mynamespace_mymodule/customer/shouldDisplayWelcome">. but it doesnt work. Did I write the code incorrect? thx :) May 24, 2017 at 13:52
  • I've changed the answer May 24, 2017 at 14:00
  • where should I add the block_id ? May 24, 2017 at 14:04
  • Like the return of the helper May 24, 2017 at 14:05
  • I updated my post ,can you please check it :) ? May 24, 2017 at 14:07

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.