Reply New Topic
2015/2/12 22:48:14
#1
Offline
Home away from home

How to hide a block when it has no contents?

Is there a way that I can make a block hide itself if it has not contents? Say I have a 'recent articles' block, which can be filtered by tag. For some tags, there are no articles, but the title of the block still displays.

What I would like to happen is, if there is no content in a block, it does not display the block title or anything else. It just doesn't display.

I've tried setting $block['title'] = '', or not returning $block, but the title still shows up.

Any ideas?


2015/2/15 7:17:36
#2
Offline
Home away from home

Re: How to hide a block when it has no contents?

Is the block returning something (like markup), even when there aren't any results? Generally, if $block.content is empty, the block will not display

_________________
Christian Web Resources
Facebook

2015/2/16 8:54:11
#3
Offline
Webmaster

Re: How to hide a block when it has no contents?

You might use also the count() function on your variables that can be empty. That could come in handy if you generate content in your block content that isn't dependent on the number of elements you want to display.

_________________

Me on Ohloh


2015/2/19 0:55:07
#4
Offline
Home away from home

Re: How to hide a block when it has no contents?

Ok thanks, the culprit was that I was passing some display preferences inside $block. Now I check to see if there are any content objects and if not, set $block = array(); and its fine.


Reply New Topic extras
 Previous Topic   Next Topic
You can view topic.
You can start a new topic.
You can reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You can post without approval.