1

I'm searching a way to define a default intro image in the Joomla article creator from the core (when a user create an article if he don't add an intro image there is one by default generated from a file in my server).


  • Template override of com_content
  • Inject into something like :
IF content.images.length == 0 
THEN
show default image
ELSE
run normal code for displaying content images
END IF

Thanks to haydenyoung on Gitter for his help.

2

You would want to put this as a template override for com_content. Depending on whether you want it to appear on the category page or single article, the file would go /templates/TEMPLATE_NAME/html/com_content/category/blog_item.php /templates/TEMPLATE_NAME/html/com_content/article/default.php

I would make a clone of existing view and then add code below to get the intro image:

<?php
$images  = json_decode($this->item->images);
$intro_image = $images->image_intro;
?>

this is check if empty and display:

<?php
if($intro_image !== '') {
       echo JLayoutHelper::render('joomla.content.intro_image', $this->item);

} else { ?>
       <div class="pull-left item-image">
            <img src="images/whatever/is/your/default.jpg" alt="something" itemprop="thumbnailUrl"/>
       </div>

<?php } ?>

I didn't have time to test, so if there is an issue, comment and I will update my answer.

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.