Get module position?

68 views
Skip to first unread message

Antony Doyle

unread,
Oct 9, 2012, 12:34:03 PM10/9/12
to joomla-de...@googlegroups.com
Hi.

I'm trying to find a way to check where a module is published and store this as a variable. Ideally, I'd like to do this in a template override.

For example, I'd like to extract and store the module position as, say, $modulePosition, and then do something like this;


if ($modulePosition == 'menu' ) {

     /*do this

}


But the problem is, I can't seem to find a way to do it. getModules($position) is listed in the docs, but I can't seem to find a way to get it to work.

Can anyone help? Is this even possible?

Thank you 

**edit: ideally, I'd like this to work in J!3.0 too. But for now, 2.5 is my priority.**

**edit again - I posted this in the Joomla Forums before I saw the notice about this group. So, sorry for the double post. **

fornandakishore

unread,
Oct 9, 2012, 12:43:32 PM10/9/12
to joomla-de...@googlegroups.com
Hi, 

Try with this : 

$module = &JModuleHelper::getModule('mod_modulename'); 
$html = JModuleHelper::renderModule($module);
echo "<PRE>"; print_r ($html);

 
Thanks & Regards

Nanda Kishore. M

Senior PHP Developer

http://php-desk.blogspot.com

Mobile: + 91 98499 71144 




--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/EhPb_K2Py3cJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Antony Doyle

unread,
Oct 9, 2012, 1:07:18 PM10/9/12
to joomla-de...@googlegroups.com
Hi, thanks for you reply. But it's not quite what I'm trying to do.

Perhaps it's my explanation. I'm not really a developer, so it may not be too clear.

I'm working in a module override file (modules.php in /templates/mytemplate/html/modules.php)

Before rendering the module I need to find out what position it is in, and then check this against a list of conditions that decide how the module should be output.

Currently I'm checking for a module class suffix. If one exists, then I output the module as default. But if there is no module class suffix, I then need to display it using different markup, but the markup changes slightly depending on where the module is.

Finding the module position is crucial to my problem. It must be stored somewhere that is accessible, surely? 

Thanks.

To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

Matt Thomas

unread,
Oct 9, 2012, 1:23:28 PM10/9/12
to joomla-de...@googlegroups.com
It sounds like you are describing module Chrome. Or, do you need finer grain control on an individual module, as opposed to module position, level? 

Best,

Matt Thomas
Founder betweenbrain
Phone: 203.632.9322
Twitter: @betweenbrain




To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/rE0XcRdlLzUJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.

Gary Mort

unread,
Oct 9, 2012, 3:26:02 PM10/9/12
to joomla-de...@googlegroups.com


On Tuesday, October 9, 2012 12:34:03 PM UTC-4, Antony Doyle wrote:
Hi.

I'm trying to find a way to check where a module is published and store this as a variable. Ideally, I'd like to do this in a template override.
 
For example, I'd like to extract and store the module position as, say, $modulePosition, and then do something like this;


if ($modulePosition == 'menu' ) {

     /*do this

}

I'm assuming that your doing this FROM your module code, correct?

If so, then the check you want is $module->position : it is already loaded.   In your tmpl folder you would create multiple templates, such as:

default.php
menu.php

then in your module code:
if ($module->position == 'menu') {
  $layout = 'menu'
} else {
  $layout = 'default'
)

Then instead of using:
require JModuleHelper::getLayoutPath('mod_custom', $params->get('layout', 'default'));

You want to call:
require JModuleHelper::getLayoutPath('mod_custom', $layout); 

The other way to do it is to add the "layout" parameter to your module's xml config file, and then you can choose from alternate layouts instead of using position as your basis for a different layout.

Antony Doyle

unread,
Oct 9, 2012, 3:28:25 PM10/9/12
to joomla-de...@googlegroups.com
Hi Matt,

The fiddling about is in the module chrome file, but it's not directly connected to the presentation of the module. Eventually I'll shift it into it's own php file, but for now it's easier to work with it here.

I'm basically wanting to query the module being displayed to find it's module position. So, if I've got a module in the 'left' position, the value of $modulePosition is 'left', if the module is in the 'menu' position, $modulePosition will be 'menu', and so on. 

Essentially, whatever is typed / selected in the module position field in the back end, I need to access that value and store it as a PHP variable.

Does this make sense?

I might be going about this the wrong way, but this is the way my brain works when solving these types of issues!!

Cheers.

Antony.


To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Antony Doyle

unread,
Oct 9, 2012, 3:33:25 PM10/9/12
to joomla-de...@googlegroups.com
Hi Gary,

That's exactly what I was after! Weirdly, I tried something very similar, but it didn't seem to work before. Maybe I mistyped something. Either way, thank you. It's much appreciated. 
Reply all
Reply to author
Forward
0 new messages