Question

I am working on delivering a customized series of messages via static blocks based on certain conditions a customer possesses.

For example, I might like to display one customized offer message vs. an alternate customized offer message depending on whether a customer is logged in, and whether they have made a purchase in the past.

I have created all of the static blocks and they all display where they are supposed to if I manually enable them. What I am wishing to learn, is how/where I can insert the conditional logic that will determine IF a block will be used or not.

I am assuming that I will need to include this or similar conditional logic on each page a customer may navigate to and on which I'd like to deliver offers or messages. Some pages will get this treatment, others will not.

I'm asking mostly about WHERE to implement the code for a non-CMS page for now.

Thanks for any help or comments.

Was it helpful?

Solution

From your question, it is not clear that where you need to display these static blocks. However based on my understanding, I will provide you some hints.

So basically you have some static blocks with you and you need to show them only when some condition get satisfied.

Here we goes. I assume you need to show these blocks in the right part of every page. For this you need to create a local.xml layout file.

File : app/design/frontend/<your_package>/<your_theme>/layout/local.xml

<layout>
    <default> <!-- this layout handle enable its child block appear almost every page -->
        <reference name="right"> <!-- this let static block appear in the right section -->
            <block type="core/template" name="conditional.static.blocks.container" template="staticblocks/contaier.phtml">
                <block type="cms/block" name="static.block.1" as="static_block_1">
                    <action method="setBlockId"><block_id>code-for-sb-1</block_id></action>
                </block>
                <block type="cms/block" name="static.block.2" as="static_block_2">
                    <action method="setBlockId"><block_id>code-for-sb-2</block_id></action>
                </block>
                <!-- continue this step for every block -->
            </block>
        </reference>
    </default>
</layout>

File : app/design/frontend/<package>/<theme>/template/staticblocks/contaier.phtml

<?php if({condition_1_satisfies}) : ?>
    <div><?php echo $this->getChildHtml('static_block_1'); ?></div>
<?php endif;  ?>

<?php if({condition_2_satisfies}) : ?>
    <div><?php echo $this->getChildHtml('static_block_2'); ?></div>
<?php endif;  ?>

<!-- continue this logic here for every static block according to your need  -->

Advantage of this method is that, it gives you great flexibility. In every page at right side you can see this block. Since we are using different conditions in the parent block , only desired static block will appear in frontend.

As I already said, this is just an idea. You can elaborate it with your own conditions.

Hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top