If module is empty, then dont show..

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
User avatar
laukilicious
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon May 22, 2006 9:48 pm
Location: Amsterdam

If module is empty, then dont show..

Post by laukilicious » Wed May 13, 2009 2:29 pm

Hi everyone,

I have a module, which is always published. Only sometimes, the module has no data. When the module has no data I dont want to show the css either.

Right now I have the following code:

Code: Select all

<?php if ($this->countModules('user7')): ?>
<div id="submenu_bg"></div>
<div id="submenu_wrap">
	<div id="submenu">
    <jdoc:include type="modules" name="user7" />
    </div>
</div>
<?php endif; ?>
Only this wont work because the module is always published.

Is there another function which I can use? Php if empty doesnt work.

Thanks in advance.

gr Laura

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11508
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: If module is empty, then dont show..

Post by ooffick » Wed May 13, 2009 4:49 pm

Hi Laura,

why is the module always published?
The only way I can see is to render the Module first, and then check if it is empty.

Code: Select all

<?php if(JModuleHelper::renderModule(array_shift(JModuleHelper::getModules( 'user7' ))) == "") :?>

Olaf
Last edited by ooffick on Mon May 25, 2009 1:31 pm, edited 1 time in total.
Reason: corrected bug in the code
Olaf Offick - Global Moderator
learnskills.org

User avatar
laukilicious
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon May 22, 2006 9:48 pm
Location: Amsterdam

Re: If module is empty, then dont show..

Post by laukilicious » Wed May 13, 2009 7:34 pm

Hi Olaf,

The module is a extended (sub)menu. It only shows data when there are submenu items.
I will try your solution and let you know, thanks!

gr Laura

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: If module is empty, then dont show..

Post by ianmac » Thu May 14, 2009 1:27 am

laukilicious wrote:Hi Olaf,

The module is a extended (sub)menu. It only shows data when there are submenu items.
I will try your solution and let you know, thanks!

gr Laura
This is an issue that has been discussed at some length in regards to Joomla! 1.5. You can find this discussion at http://groups.google.com/group/joomlabu ... 4a285963c7

There is a proposed workaround that you may find helpful.

Cheers,
Ian

User avatar
laukilicious
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Mon May 22, 2006 9:48 pm
Location: Amsterdam

Re: If module is empty, then dont show..

Post by laukilicious » Thu May 14, 2009 8:19 am

@Olaf, I'm getting an error:
Fatal error: Can't use function return value in write context in []templates\sysqa\index.php on line 60

I will check the discussion now.. :)

User avatar
ooffick
Joomla! Master
Joomla! Master
Posts: 11508
Joined: Thu Jul 17, 2008 3:10 pm
Location: Ireland
Contact:

Re: If module is empty, then dont show..

Post by ooffick » Thu May 14, 2009 8:31 am

Sorry, you the empty function doesn't work, and I think the modChrome one is much nicer, but you could try this:

Code: Select all

<?php if(JModuleHelper::renderModule(array_shift(JModuleHelper::getModules( 'user7' ))) == "") :?>
Olaf
Olaf Offick - Global Moderator
learnskills.org

bt-t
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Fri Jul 24, 2009 8:35 am
Contact:

Re: If module is empty, then dont show..

Post by bt-t » Tue Jul 28, 2009 10:09 am

Please note that the test under:
<?php if ($this->countModules('user7')): ?>
checks if there is any module published at the position "user7". so if you have other modules published at that same position the code between the if-test will always display... I hope it helps you understand your problem better...Good luck!

aaronrrc
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Sun Sep 07, 2008 4:40 am

Re: If module is empty, then dont show..

Post by aaronrrc » Tue May 17, 2011 2:17 am

Thanks Olaf, Im now in the right way!


Locked

Return to “Joomla! 1.5 Coding”