Page 1 of 1

load module position in component layout template

Posted: Thu Oct 01, 2009 2:33 pm
by Sergey Romanov
Hello,

I have strange thing. If i insert in to my template

<jdoc:include type="module" name="breadcrumbs" />

Then I see reeal breadcrumbs like Home->Category->Article but if I insert

<jdoc:include type="module" name="user1" />

Or any other name nothing happen. I would understand when it ia always nothing but some (breadcrumbs) module position it encapsulate and otyher not.

What is the good way to insert module position in component layout template or subtemplate?

Re: load module position in component layout template

Posted: Thu Oct 01, 2009 3:53 pm
by imanickam
The syntax basically says render all the modules that are published in the position mentioned in the parameter name - remember, it is not the name of the module; rather it is the name of a module position.

I believe that you have a module published to the module position breadcrumbs. That is the main reason you are seeing the module.

Do you have modules assigned to user1 and other module positions? If not, you will not see any modules.

Re: load module position in component layout template

Posted: Fri Oct 02, 2009 4:13 am
by Sergey Romanov
Of course I have module assigned in the position I try to load.

How I use this function

Code: Select all

function load_module_position( $position, $style = 'xhtml')
{
	switch($style)
	{
		case 'table':
			$style = 1;
			break;
		case 'horz':
			$style = 1;
			break;
		case 'none':
			$style = -1;
			break;
		case 'xhtml':
			$style = -2;
			break;
		case 'rounded':
			$style = -3;
			break;
		default:
			$style = -2;
			break;
	}

	$document	= &JFactory::getDocument();
	$renderer	= $document->loadRenderer('module');
	$params		= array('style'=>$style);

	$contents = '';
	foreach (JModuleHelper::getModules($position) as $mod)  {
		$contents .= $renderer->render($mod, $params);
	}
	return $contents;
}
and in templates

<?php echo load_module_position('user12', 'xhtml'); ?>

Re: load module position in component layout template

Posted: Fri Oct 02, 2009 12:35 pm
by ooffick
Sergey Romanov wrote: <?php echo load_module_position('user12', 'xhtml'); ?>
Why do you want to make it so complicated? What is wrong with the normal way?
You might want to open the module which is published in the module position user1, and write into the position field the following:

Code: Select all

user1
Yes, you can write into this dropdown field. (don't select it, just delete the entry which is there and write user1 into it)

And then click on save.

Olaf

Re: load module position in component layout template

Posted: Tue Jun 18, 2013 7:51 pm
by deltadan79
Hey Guys,

I've found a solution that works to add a module position to a component manually where the typoical method does not work. Similar in concept to the loadposition principle. Sometimes you'd like to add a module/position to a components layout page and of course loadposition does not work many times. After heargin a lot of the answers i constantly end up going back to this one as it seems to work every time. But i always forget where i found it. so im posting it here for others to see. Thanks to the person who originally suggested as i can't remember now :)

Code: Select all

<?php $document = &JFactory::getDocument();
$renderer   = $document->loadRenderer('modules');
$position   = 'custompositionname';
$options   = array('style' => 'raw');
echo $renderer->render($position, $options, null); 
?>