0

How would i wrap this in an IF statement so it displayed a message if there is no text in the PDF attribute ??

<?php $_pdf = $this->getProduct()->getPdf(); ?>
<?php if ($_pdf): ?>
    <h2><?php echo $this->__('PDF') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_pdf, 'pdf') ?>
    </div>

<?php endif; ?>

I know this is an easy question but i am new to magento and PHP so i am struggling to work this out.

Thank you in advance

  • if(empty($_pdf)) .... ;) gl hf – Stefan Gregori May 28 '14 at 10:31
4

You probably want to do something like this:

<?php $_pdf = $this->getProduct()->getPdf(); ?>
<?php if ($_pdf): ?>
    <h2><?php echo $this->__('PDF') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_pdf, 'pdf') ?>
    </div>
<?php else: ?>
    There's no PDF associated with this product!
<?php endif; ?>
| improve this answer | |
  • i was writting "<?php else ?>". Now i see where i was going wrong. Thank you this should help in the future as well so thank you – Adam Allen May 28 '14 at 13:38
  • never forget the colon :)! or use { } to start and end the block. <?php else: ?> – Pronto May 28 '14 at 13:39

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.