Hide an empty block

Permalink
Hi everyone, I have an issue which probably has a simple solution but I can't find it! Basically, I have a blog entry page with a thumbnail image block at the top. I need this to only display if an image has been chosen for the block. I.e. hide the block if it's empty/there is no image selected. Can anyone help with this?

I have tried
<div class="image-link">
  <?php      
  $a = new Area('Thumbnail Image');      
  if ($a->getTotalBlocksInArea($c) > 0 ) {
    $a->display($c);   
  }   
?>
</div>


The original code for the thumbnail is:
<div class="image-link">
  <?php            
  $a = new Area('Thumbnail Image');
    $a->display($c);      
  ?>
</div>

gracehcoote
 
gracehcoote replied on at Permalink Reply
gracehcoote
Right well, at the lack of any answer here, I've had to just resort to jQuery and use the following code to hide any image divs that don't actually contain an image:

$('div.image-link').not(':has(img)').hide();


Not ideal, bit hacky, but it'll have to do.
gracehcoote replied on at Permalink Reply
gracehcoote
Right well, at the lack of any answer here, I've had to just resort to jQuery and use the following code to hide any image divs that don't actually contain an image:

$('div.image-link').not(':has(img)').hide();


Not ideal, bit hacky, but it'll have to do.
mnakalay replied on at Permalink Reply
mnakalay
I assume you are using the core image block so I don't understand the problem because that block will only output something if you're in edit mode OR if an image is selected. If no image is selected, it doesn't output anything.

If you want a less hacky solution than yours, could you give more detail?
gracehcoote replied on at Permalink Reply
gracehcoote
I think it is the core image block yes, but I have to apologise, I'm not great at this stuff :p

Using the following code makes the image not show up at all unless in edit mode:

<?php      
if ($c->isEditMode()) {
  print '<br><br>';
  $a = new Area('Thumbnail Image');
  $a->display($c);
}
?>


Am I missing the part for if an image is selected?
mnakalay replied on at Permalink Reply
mnakalay
all the code you have been showing is code from the page itself, not from the image block. IF you want the image to appear or not, you need to work on the image block, not on the page itself.

But again, when no image is selected, the image block just shows nothing so I am not sure what you are trying to hide;
gracehcoote replied on at Permalink Reply
gracehcoote
For some reason, that's not the case. When an image is not selected the text "Image not found" shows up. I'm not sure why this is, but I'll take your advice and look at the image block code instead.
mnakalay replied on at Permalink Reply
mnakalay
Maybe I should have started with that: what version of Concrete5 are you using?