Matt
Matt

Reputation: 1757

Show Slider Unless Upsells Exist - PHP if Statment

I am using this code below:

<div class="feat-product">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('feat_products')->toHtml() ; ?>
</div>
<div id="products-recently-viewed" style="border-bottom:1px dashed #ccc; padding-bottom:10px;">
        <?php echo $this->getChildHtml('upsell_products') ?>
</div>

At the moment you can see both blocks are being shown, I want to make it so only the feat_products always shows UNLESS there are products in the Upsell of the product which in that case I need it to not show the feat_products and ONLY show the upsell section.

Hope someone has stumbled across this before and can help out.

Upvotes: 0

Views: 578

Answers (1)

Steven Hunt
Steven Hunt

Reputation: 2321

In PHP, you can embed conditionals and put html in the middle. For instance:

<?php if (strlen($this->getChildHtml('upsell_products')) > 0) { ?>
<div class="feat-product">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('feat_products')->toHtml() ; ?>
</div>
<?php } ?>

I am presuming that your getChildHtml function returns an empty string if there are no products. Tweak as needed...

Upvotes: 2

Related Questions