Page 1 of 1

Display image in sub category blog view only if file exists

Posted: Mon Mar 18, 2019 11:27 am
by ginevra
I try to insert this code in my ovveride of blog_children.php to display images in the blog view sub category:

Code: Select all

<?php echo '<img src="'.json_decode($child->params)->image . '" />'; ?>

It works well, but if the image is not present, the missing image icon appears, while I'd prefer the image to not show up at all.
I tried to insert this one too:

Code: Select all

<?php if ($this->params->get ('show_image') && $item->getParams()->get('image')) :?>
<?php echo '<img src="'.json_decode($child->params)->image . '" />'; ?>	
	<?php endif;?>	
but no images appear in any sub category
I use latest joomla version 3.9.4
Could you please give me some code that specifies to show the image only if it exists or any suggestion?

Re: Display image in sub category blog view only if file exists

Posted: Tue Mar 19, 2019 1:54 pm
by sazbaztaz
Not sure how the blogview template looks like but I'd approach the solution with print_r and see what options are there.

<?php echo '<pre>'; ?>
<?php print_r($this->params); ?>
//or / and
<?php print_r($this->item); ?>
<?php echo '</pre>'; ?>

Hope it helps.

Re: Display image in sub category blog view only if file exists

Posted: Wed Sep 25, 2019 12:41 pm
by natipmoraes
Try this

<?php echo '<img src="'. json_decode($item->params)->image .'" />'; ?>