Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Display / disable module bases on height of another module

Display / disable module bases on height of another module

I would like to show or disable a metamod module based on the height of a menu module.
The menu module shows a vertical (sub)menu. Based on the height of this module (or the number of menu items) i would like to disable the module below the menu, to create more space for the menu.

I would like to do the same with the main content (component). Below the main content is a module. Also based on the height (or total amount of characters) of the maincontent, the module must be shown or disabled.

Thanks in advance.

evolve
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Display / disable module bases on height of another module

Hi evolve,

That's a difficult one. I've never attempted to base the selection of modules in a MetaMod on the final output of a different module.

In particular, you're not going to get access to the actual rendered height of the other module. That's only going to be calculated as the module's HTML gets rendered onto the page at the client side. At that point it becomes available via JavaScript, but by then it's too late for MetaMod to use the information, since the page has been calculated and sent to the client.

Another way of looking at this, since you're talking about expanding sub-menus, is to think about what page you are on at any given time. If the page (menu item) is one of the expanding ones then you can do a quick calculation about how many items must be showing.

So let's say you have the following menu structure:

Home  (id:1)
Sports (id:2)
- Rugby (id:3)
- Cricket (id:4)
- Baseball (id:5)
- Motorsports (id:6)
- Athletics (id:7)
News (id:8)
- recent (id:9)
- archived (id:10)
About Us (id:11)
Contact Us (id:12)

Now, let's say the submenus are expanding ones. If you are not on one of those pages then you only see the top level items.

You know that if the current menu item (Itemid) is 1, 11 or 12, then the menu height is "5 items".

If the current menu item is 2, 3, 4, 5, 6 or 7 then the 1st submenu will be showing, and the total # of items is 10. You could also say "if the current menu item is, or descends from Itemid 2"...

If the current menu item is 8, 9 or 10, then the 2nd submenu will be showing and the total # of menu items is 7. You could also say "if the current menu item is, or descends from Itemid 8"...

So now we're getting somewhere. JomGenius gives us some tools to check if the current menu item descends from a particular menu item.

So I'd code it this way:

$count = 5; // # items in collapsed menu
if ( $Itemid == 2 or $menu_genius->check("parentitemids = 2")) $count = 10;
if ( $Itemid == 8 or $menu_genius->check("parentitemids = 8")) $count = 7;
if ( $count == 5 ) return "XXX, YYY"; //show these 2 modules if menu not expanded
if ( $count == 7 ) return XXX; //show only this module if news menu expanded
return; // return NO modules if the other menu was expanded.


Remember to replace XXX and YYY with the module ids of the modules you actually want to display - and don't forget to customise all the other menu ids and other numbers to suit your menu setup.

You can find out the different Itemid values for each of the menu items by looking in the menu manager. The Itemid is shown in the last column in the list of menu items.


I hope that helps,
best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Display / disable module bases on height of another module

Hi Stephen,

Thanks for the excellent reply.

The Menu is as followed:

1
- 2
- 3
-- 4
-- 5
- 6
-- 7
-- 8
-- 9
-- 10
-- 11
-- 12
13
- 14
-- 15
-- 16
-- 17
-- 18
-- 19
- 20
Etc.

1st level menu items is a horinzontal menu.
2nd level menu items is a seperate vertical menu.
3rd level menu items is a seperate vertical menu.

When the 3rd menu has more than 4 menu-items, the metamod module should be disabled.

What should be the code for this?


Then the second question.
This website has a fixed height, that's the reason the metamod modules have to appear or disapear sometimes.

When the maincontent (article) becomes longer then x characters, the metamod module has to disappear.
Is this possible? If so, how?

Again, many thanks in advance.

Best regards,
Kai

evolve
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Display / disable module bases on height of another module

Hi Kai,

1st question: I think the easiest way is just to detect if the user is on the particular menus that have more than 4 3rd level menu items. If it's NOT, then you include the module. If it IS, then you don't include the module. This basically means it's turned off when you are on that menu.

So:

// add more menu ids to the lists that contain 6,14
// if you have more 2nd-level menu items with more than 4 sublevels.
$on_long_menu = (
  $menu_genius->check("itemid = 6,14")
  or $menu_genius->check("parentitemids = 6,14")
);
if (! $on_long_menu ) return XXX; // replace XXX with module id to show/hide.


2 - it's possible to get hold of the HTML of the main article, and to count the characters. You can even strip the html tags from it to give a more accurate (though not perfect) count. Hopefully this will be good enough.

Try this code:

$document =& JFactory::getDocument();
$buffer = $document->getBuffer();
$content = strip_tags($buffer['component']['']);
$length = strlen($content);
if ($length < 1000) return XXX; // only show module XXX if article is <1000 chars.

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Display / disable module bases on height of another module

Thanks Stephen,

The solution for my second question is spot on!! Fantastic!

For the 1st question i'm not really sure if that is what i want.
My client is gonna maintain the website, so if he creates a new 3rd level on a menu which already has 4 items (so he makes the 5th item) i have to manually adjust the metamod module. If there's no other way to work around this, than this is fine.

Many thanks for your amazing help!
It's worth every penny of the $22 !!

Kind regards,

Kai

evolve
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Display / disable module bases on height of another module

Hi Kai,

it's theoretically possible to automatically count the number of subitems in the current menu or its parent, but I'm running really short on time at the moment (preparing the the Joomla & Beyond conference next week, at the start of a 3 week around the world work trip). Can you remind me again in about 3 weeks to take a look at this again?

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1685
Total Polls:
6
Total Posts:
5940
Total Posts Today:
1
User Info:
 
Total Users:
5186
Newest User:
Totosite
Members Online:
0
Guests Online:
124

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked