Loading a module in another module in Joomla - joomla

I'm an absolute beginner using Joomla. I'm trying to load a module within another module but I can't find how to do this. I've been trying adding
{loadposition position}
with "position" replaced the position of the module I'd like to be loaded but it seems to work only in articles.
I've found another solution here : http://forum.joomla.org/viewtopic.php?p=1531754&sid=bae9b487983c7e8a9f9c4fbd2958cf52#p1531754
but I don't know where to put this PHP code in my module.
Thanks for helping !

You need to manually add the code to render your inner module to your container module. Heres an example:
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mainmenu');
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $module, $attribs );
Taken from:
http://docs.joomla.org/JModuleHelper/renderModule
To display the output you would need to place the code in the section of your outer module source that you want the html to be rendered.
Where you would replace 'mainmenu' with the name of the module that you want to embed. (I removed the second param, as I'm assuming you don't want to display a title).

If you need to bring another module other than the menu (every where always show you a module)
This is my trick: (works in 2.5 and 3.0)
Go to your module and create a fake position only for this like "oehelp" in this case.
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$options = array('style'=>'raw');
echo $renderer->render('oehelp',$options,null);
voila,
saludos

Related

Including Joomla! 3 module in custom position on custom component

I've seen alot of examples of how to include modules on a custom joomla! component using JModuleHelper::getModules, however, when trying to include modules in a custom position, the array come back empty. Here's my code in my component's template:
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('comwhcustomer');
foreach ($modules as $module){
echo JModuleHelper::renderModule($module);
}
?>
You'll notice the position I'm passing the getModules function is comwhcustomer. This code is returning a blank array. If I pass "footer", I do successfully get the module in the footer position.
I'm using an adapted protostar tempalte and I have added the comwhcustomer position to the xml definition file for the template. I've created the module in module manager and in the position filed, I've selected the "comwhcustomer" position that shows up in the dropdown. On the modules manager page, I see the module listed in the position selected (comwhcustomer). I've confirmed in the database table #__modules that the position is saved correctly.
However, the array is still coming back empty on the getModules call. What am I missing?
Joomla version 3.4.1
Local environment
Windows IIS
PHP 5.4.24
MySQL db
PS - As an alternative, I have sucessfully loaded the module with JModuleHelper::getModule() however, none of the attributes I define in the module manager come over, because they're not supposed to. I'd like to use the method mentioned above so I can control the module behavior from the manager rather than attributes in the code, because this position will be used in multiple views of this component.
This is my first time posting to SO. I do appreciate the support :-)
itoctopus, you were exactly right! The module itself was not assigned to any pages, that's the piece I was not taking into consideration! Thank you so much for your help! I set it to display on all pages and it worked!
Of course, it doesn't show up on all the other pages because they do not contain a position called "comwhcustomer" so it is exactly what I was looking for!

Edit JomSocial Joomla Registration Page & Adding Content

I'm running JomSocial 3.2 on Joomla 3.
I want to add some content to the right side of the registration page.
Some pictures and other contents.
So far, i've been able to get to the "register.index.php" file,
which is the file that displays some of the content in the homepag.
The file is in: "/site_root/components/com_community/templates/default/" folder
but i've not been able to fully edit the whole registration page.
This could be done in many different ways - even without editing any file. Install this extension: http://extensions.joomla.org/extension/advanced-module-manager and when editing module you'll have additional tab called "tasks" There will be field URL, type inside URLs of your registration form. Thanks to this you'll be able to assign modules to registration form.
You could also override for:
ROOT/components/com_community/templates/default/register.index.php
Copy it to:
ROOT/templates/your-template/html/com_community (if you don't have "html" or "com_community" folders, feel free to create them)
Then you may create module position inside file using this code:
$modules = JModuleHelper::getModules( 'reg-positon' );
foreach ($modules as $module) {
$_options = array( 'style' => 'xhtml' );
echo JModuleHelper::renderModule( $module, $_options );
}
Above code creates module position: "reg-positon'. You'll need to type this name manually as it will be not listed on module positions list.
Now you'll need a bit of html to display it on right or left of registration form.

joomla Modules - Between Article or inside Article? What is correct?

I want to place articles and modules on my page. It should look like my scatch:
I am wondering if i can make 4 articles and one module (information box) and place this inbetween those articles, Or should i just create one article wich looks like the hole area (article 1-4 + INformation box)? So far i have tried to do {loadposition infobox-pos} into article 2. But than the box-width is not 100% but 50%.
Than aggain if i would make one big article with the contents from article 1-4 it would not fit great into my responsive layout.
I use T3-Framework.
Joomla doesn't support this natively, since module output is controlled by the template, and component output (in this case, com_content, view=category, layout=blog) is handled before modules are rendered.
You can proceed in many ways, I am listing them in order of decreasing ease:
Write a jquery script that moves the pieces in the browser. You could also use mootools and it's bundled with joomla, but odds are you already have jquery loaded anyways.
Write a view override for abovementioned view: so copy /components/com_content/view/category/tmpl to /templates/your_template/html/com_content/category (copy all files). Then edit blog.php and insert your module there, use something like /plugins/content/loadmodule/loadmodule.php :
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$modules = JModuleHelper::getModules($position);
$params = array('style' => $style);
foreach ($modules as $module) {
echo $renderer->render($module, $params);
}
Write a content plugin
you can also use {loadmodule YourCustomModuleTitle} and place this in <div> with custom style attributes like
<div style="width:100%;float:right">{loadmodule MyModule}</div>
or
<div class="something">{loadmodule MyModule}</div>
Note: the module which loaded must be assigned to the same menu item or "all"

How to use breadcrumbs in Joomla in custom components?

I wrote simple component by this example, but when i entering it i see Home instead of my components name.
And also is it possible to get deeper, for example joomla->my_component->some_other_component, but exactly after mine.
P.S.
Found http://docs.joomla.org/How_to_add_breadcrumbs, but how use it automatically in every view?
Try this:
$mainframe = &JFactory::getApplication();
$pathway =& $mainframe->getPathway();
$breadcrumb = $pathway->setPathway(array());
$pathway->addItem( JText::_( 'YOUR_BREDCRUMB_ITEM' ),'');
Replace YOUR_BREDCRUMB_ITEM with your item name. Hope this will help.

Place certain article anywhere in joomla template

Is it possible in Joomla to place a certain article in a template, additionally to the normal content? I want the article to show up on every page.
You can simply take it from the databse and print its content. In the template, where you want to show the article, write this:
$id=/*Id of the article to show*/;
$db=&JFactory::getDBO();
$db->setQuery("SELECT * FROM #__content WHERE id=$id");
$item=$db->loadObject();
echo $item->introtext;
UPDATE: ENABLE PLUGINS
I can't find where i've used that code and i can't copy-paste it, so i try to write it again by looking at the view.html.php of the com_content:
JPluginHelper::importPlugin('content');
$dispatcher =& JDispatcher::getInstance();
$params = &$mainframe->getParams();
$dispatcher->trigger('onPrepareContent', array (&$item, &$params, 0));
//The last line triggers the onPrepareContent event, so if it does not work maybe you need other events, so try with onAfterDisplayTitle, onBeforeDisplayContent or onAfterDisplayContent
Have you seen this? http://extensions.joomla.org/extensions/news-display/content-embed/7528
It allows you to place any article as a module on your Joomla site. And with modules you can have them displayed site wide.

Resources