I would like to add a tag around the intro text, but only if the article has an intro image.

It's easy to add markup around the image in the intro_image layout file. And in the file blog_item.php, I can see where the text is included:

<?php echo $this->item->introtext; ?>

But can anyone help me write an if statement so that I can add a <div> around the text so that I can control the layout if the intro image has been set?

  • Sorry, that bit of php doesn't show up right in the post - I don't know how to add it correctly but I hope you know what I mean.
    – LeilaH
    Commented Jun 8, 2018 at 14:43

1 Answer 1


If you mean the intro image that's used in intro_image layout, use the same check as in the layout:

<?php $images = json_decode($this->item->images); ?>
<?php if (!empty($images->image_intro)) : ?>
    <div><?php echo $this->item->introtext; ?></div>
<?php else : ?>
    <?php echo $this->item->introtext; ?>
<?php endif; ?>
  • No, I want to put a div around the text, but ONLY if there is an image. If there's no intro image, no div around the text. Basically, I want a column effect if there is an image.
    – LeilaH
    Commented Jun 28, 2018 at 11:17
  • Yes, that's what this snippet does. Replace <?php echo $this->item->introtext; ?> line with it.
    – Sharky
    Commented Jun 29, 2018 at 13:38
  • Many apologies, I mis-read it. It works perfectly! Thank you so much.
    – LeilaH
    Commented Jul 2, 2018 at 8:00

Your Answer

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

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