1

A client web site uses a Joomla template with lots of modules in the left column, but for the custom component I'm designing, those modules must be replaced by a vertical menu. The hack solution I came up with is to hide those modules with CSS:

div#leftpad > div {
    display:none;
}

and then insert a <div id='compmenu'> in <div id='leftpad'> with javascript and set display:block. With jQuery, I could do

jQuery('#compmenu').appendTo('#leftpad').show();

The component displays a google map, so javascript is required anyway. Any Joomla experts here know of a more elegant or straightforward method to achieve the same result?

yitwail
  • 1,999
  • 3
  • 20
  • 27

2 Answers2

1

Why don't you use the build in Menu-Bind for Modules to hide them when your Module or Component is displayed, this would be a clean way. I think your Module/Comp is bound to a Menu item.

Edit: For sure your client have to implement your Module/Comp the right way. Is is very bad to do something like this with a hack.

  • Create Menu-Item for your component (programtic)
  • Create a hidden menu
  • Add your component to that menu
  • Do unbound all modules from this menue

The Joomla API hold a good series of Tutorials about building components. I gone through them in the past but as I see they have improved them. As I understand your component is relatively straight forward so the default menu should be what you want. It is described in the install XML

 <administration>
  <!-- Administration Menu Section -->
  <menu>MyMenuLink</menu>

  <!-- some other stuff -->

 </administration>

And will be available at the Joomla! menumanager after your client has installed your component. So I think it will be not that hard for you.

sra
  • 23,820
  • 7
  • 55
  • 89
  • Can you provide a small code fragment? Or perhaps a class method I can look up in the API docs? My knowledge of Joomla isn't comprehensive unfortunately. My component wouldn't necessarily have a menu item. It might be called from an image link on the home page, for instance. – yitwail May 16 '11 at 08:43
  • @yitwail you must always use a menulink in joomla even if it's not a visible menu. All other can lead you bad behavior. As far as I understand you are developing a component so the client will need to install it. And handle all in the joomla backend. It's not up to you. You don't have to do anything. It's simply not the way joomla works. A little background: each Module in joomal has a MenuBinding with default the 'bind to all' default for each menu. The Client only has to unbound it for the Menu (or Menuitem) which reference your component. – sra May 16 '11 at 09:11
  • I would prefer not to use a hack. That's why I asked the question. I tried googling 'joomla menu-bind module' and the first result mentioned specifying itemid=xx in the url. Then I came across an official looking document about this [here](http://docs.joomla.org/How_to_control_module_display_when_linking_to_an_article_with_no_menu_item) but it's addressing article pages specifically. Anyway, I need to somehow create an itemid for the component that excludes the modules it doesn't need? – yitwail May 16 '11 at 09:23
  • @yitwail The Joomla API you have linked describes a default compenent (com_content) that is addressed to view a article. But the problem is not exactly like yours cause it's about article. But you will be able to solve it with this solution, and as you might notice it is the same solution I advised you. For details see my edited Answer – sra May 16 '11 at 09:33
  • @sra, you posted your last comment while I was writing my own, so my last comment is a little out of sync. My 'client' is actually a web design business who knows much more joomla than I do, but I create components when he's busy doing other things, so I will ask for his input. In the meantime, thanks for your insight. If he objects to the 'hack' then I will *have* to do it properly, but I'm paid hourly so he may prefer a quick hack. – yitwail May 16 '11 at 09:35
  • @yitwail OK, not matter. Maybe you can keep me informed about this? – sra May 16 '11 at 09:43
  • @sra, my client agrees with you. But how's this for a compromise: I will create the hidden menu, etc. needed to generate an itemid with which I will exclude all modules. Then, I'll insert my menu with javascript. Or must I create an additional module just to make a menu, and create a dependency between the module & the component? – yitwail May 17 '11 at 00:38
  • @sra, thanks. I already have an admin menu like that. I didn't realize I could use it for the itemid. One more question, and I'll be gone. If there are any modules that have a *Menu Assignment* to *All Menus* in *Module Manager*, then user has to change it to *Select Menu Item(s) from the List* and individually select all menus except *MyMenuLink*? – yitwail May 17 '11 at 16:09
1

In Joomla, menu types are determined by the various Views specified by the installed components. If your component is properly coded to Joomla MVC standards, you should have at least one View, which will give you at least one menu type to choose from. As sra mentioned, even if you do not need a menu link, you should create a hidden menu so you can create a link so you have an itemID to work with and assign modules to.

There are a few extensions and websites that can help create the necessary files for a component so all you have to do is add a little code. Once you understand the Joomla MVC it's really not too difficult.

http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1

Doing it this way will save you a lot of headache later when the end user has to figure out how to use your component.

Brent Friar
  • 10,588
  • 2
  • 20
  • 31
  • Brent, I'm well aware of MVC. My component has a map view containing views/map/view.html.php & views/map/tmpl/default.php. I've studied some version of the tutorial you mention. Anyway, thanks for the input; I will bite the bullet & do it the right way. – yitwail May 17 '11 at 00:34