1
C6_chus
Would like to hide a block depending on its content
  • 2007/11/1 1:36

  • C6_chus

  • Just popping in

  • Posts: 10

  • Since: 2006/9/12


Hy I would like to hide a block depending on its content.

Lest say I maid a vwar block for including nextactions of the vwar script (event script) in a block.
I would like that if there are no upcoming events that the block isn’t shown at the web site. At the moment. If the block returns no events I have an empty block with title. I would like to hide the complete block when it is empty there a no events.

Is there any xoopsoption or variable within a block I can set to hide a block so it is not shown?


I not sure if its the right forum, sorry if i missed.

Many thanks for your help.

;)

2
Catzwolf
Re: Would like to hide a block depending on its content
  • 2007/11/1 1:52

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


I suggest your best bet would to be look in class/themes.php, class/themes.blocks.php (depending on your version of Xoops) and and the class/xoopsblocks.php for code you could modify or use for this.

There are two methods in class/xoopsblocks.php that you might want to take a good look at, getContent() and buildBlock().

You could create a block function (within your block parms) and test this function for a true or false to see if your script is empty. That way your block will show or not.

Hope this little helps

Catz

3
zyspec
Re: Would like to hide a block depending on its content
  • 2007/11/1 3:27

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


It really depends on how your block is written - I've done something similar to the following in a block template for some blocks I've created:

<{if (!empty($block.contents))}>
  <
div>
    
display block contents
  
</div>
<{/if}>

This will only display the block if the contents aren't empty...

4
snow77
Re: Would like to hide a block depending on its content
  • 2007/11/1 3:54

  • snow77

  • Just can't stay away

  • Posts: 864

  • Since: 2003/7/23


I can tell you how to hide it completely but not depending on it's contents...it would be more like Zyspec's way for it to be dynamic... the trick would somewhere in the <{if}> I think, but don't take me for sure, it's little what I know of smarty.

To hide it completely, here is an example (hiding a block titled navbar):

<{if $block.title != 'navbar'}>
<{if 
$block.title}><div class="xo-blocktitle"><h3><{$block.title}></h3></div><{/if}>
<
div class="xo-blockcontent"><{$block.content}></div>
<{/if}>


If you could find a way to do it by smarty variables I think it could be much simpler.
www.polymorphee.com
www.xoopsdesign.com

5
Catzwolf
Re: Would like to hide a block depending on its content
  • 2007/11/1 5:25

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Quote:

snow77 wrote:
I can tell you how to hide it completely but not depending on it's contents...it would be more like Zyspec's way for it to be dynamic... the trick would somewhere in the <{if}> I think, but don't take me for sure, it's little what I know of smarty.

To hide it completely, here is an example (hiding a block titled navbar):

<{if $block.title != 'navbar'}>
<{if 
$block.title}><div class="xo-blocktitle"><h3><{$block.title}></h3></div><{/if}>
<
div class="xo-blockcontent"><{$block.content}></div>
<{/if}>


If you could find a way to do it by smarty variables I think it could be much simpler.


I agree with you, but I wasn't sure if he wanted to do the check before the block was processed or not. Because doing it the smarty way just 'hides' the block not actually prevent it from being processed and taking up more array space. In reality it would be easier if there was a config to allow the admin to turn off blocks without any content.

ATB

Catz

6
Will_H
Re: Would like to hide a block depending on its content
  • 2007/11/1 11:14

  • Will_H

  • Friend of XOOPS

  • Posts: 1786

  • Since: 2004/10/10


As a designer, I would utilize the smarty technique, but for my own sites it would be a core hack.

We really should start to compile a list of community requested core inclusions. Because there are just too many things this cms cannot do without hacking the core.

I agree with catz, it doesn't make sense to hit the db for no reason.

7
C6_chus
Re: Would like to hide a block depending on its content
  • 2007/11/1 13:30

  • C6_chus

  • Just popping in

  • Posts: 10

  • Since: 2006/9/12


Thanks a lot guys. I think your tips will be of a great help so far.
To avoid confusions, in my case I have to process the block to know it is empty.

May thanks again.

;)

Login

Who's Online

235 user(s) are online (159 user(s) are browsing Support Forums)


Members: 0


Guests: 235


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits