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.

  • 1
    How are you calling your static block?
    – mbalparda
    Sep 4, 2014 at 3:32
  • give more detail regarding codes
    – Amit Bera
    Sep 4, 2014 at 3:38

1 Answer 1


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

    <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 type="cms/block" name="static.block.2" as="static_block_2">
                    <action method="setBlockId"><block_id>code-for-sb-2</block_id></action>
                <!-- continue this step for every block -->

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

  • You got me jump-started. Thanks. The pages I am targeting are Home, Account, Category, Product, and Thank You. The conditions that need satisfying vary for each page, and the locations I am placing the blocks vary from page to page, but are essentially always the same for any single page type (e.g., blocks on home page are always in the same places, but content of block can vary), blocks on category page are in different location than home page (you get the idea). Your hints are solid and I'm pretty sure I can adapt them for what I'm trying to do. Thx.
    – Dave G
    Sep 4, 2014 at 5:14

Your Answer

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

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