0

On my k2 pages I needed module complete on the top area, a module assign is not possible because the pages are dynamicly from the DB selected. So I installed a module like "loadmodule", the difference is simple I can get module with specific id.

For example: {loadmodulefromarticle|97} if I use it in the extra fields or in the content area then it works, but as written I need it in the top area of my page, so I have an if request and try load k2 content on the top. I get content and that's ok. But I see here only plain text and the module is not loaded. My question is, what is to insert here so that I get the module loaded? I think it can be something around to $result;

<?php
    $menuID = JSite::getMenu()->getActive()->id ;

    if ($menuID == '713') {

        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('introtext');
        $query->from('#__k2_items');
        $query->where('id = ' . JRequest::getInt('id'));
        $db->setQuery($query);
        $result = $db->loadResult();
?>
                <div id="gkHeaderMod">
                    <div><?php echo $result; ?></div>
                </div>
<?php
}
?>
Shaz
  • 2,647
  • 2
  • 35
  • 45
Nicky R.
  • 23
  • 4
  • Your coding is getting content from the K2 database table, however where is the code to display the module? – Lodder Oct 22 '13 at 21:26
  • The code is the placeholder which is in the "introtext" field stored, and i get this code in the frontend as plain text, i see only: "{loadmodulefromarticle|113}" – Nicky R. Oct 22 '13 at 21:32
  • Ahh I see. Why not use `JModuleHelper::renderModule()` ? Also I would use Joomla 2.5+ coding standards for getting the menu ID – Lodder Oct 22 '13 at 21:34
  • I'm newbe with joomla dev. can i implement it in my code? – Nicky R. Oct 22 '13 at 21:36

1 Answers1

0

You could do something like the following. It uses Joomla coding standards to get the menu ID and renderModule to display the module.

<?php
  $app   = JFactory::getApplication();
  $menuID   = $app->getMenu()->getActive()->id;

  if ( $menuID == '713' ) {
        $db = JFactory::getDbo();
        $query = $db->getQuery(true)
         ->select('introtext')
         ->from('#__k2_items')
         ->where('id = ' . JRequest::getInt('id'));
        $db->setQuery($query);
        $result = $db->loadResult();

        echo '<div id="gkHeaderMod">';
        $module = JModuleHelper::getModule( 'mod_example', 'Module Title' );
        echo JModuleHelper::renderModule( $module );
        echo '</div>';
  }   
?>

Note that you will have to change mod_example and Module Title to whatever you require

Lodder
  • 19,758
  • 10
  • 59
  • 100
  • can i say here, module: mod_image_show_gk4 with id 113 because i have more modules from mod_image_show_gk4 – Nicky R. Oct 22 '13 at 21:48
  • I'm a little confused. Was that a question? Please explain – Lodder Oct 22 '13 at 21:51
  • if i use placeholder {loadmodule header_fix} so i get all modules from this position, i have installed a plugin where i can say {loadmodulefromarticle|30} and i get module with this id, so can i have more modules on 1 position and get only module which i need. if i use this code in extrafields of k2 or in the content are i get module and that's ok, through this code the module with specific id is not loaded and i see only placin text "{loadmodulefromarticle|30}" – Nicky R. Oct 22 '13 at 21:57
  • It won't work using the placeholder `{loadmodulefromarticle|30}` in your article and then echoing that our from a database query. Plugins don't work like that – Lodder Oct 22 '13 at 22:04
  • sorry, but last question, exist any way to load specific module so how i need? Otherwise i must work with position absolute... – Nicky R. Oct 22 '13 at 22:08
  • Have a look at the last bit of my answer. That's the exact code you use to render a module. As mentioned, you will need to change **mod_example** and **Module Title**. – Lodder Oct 22 '13 at 22:10
  • The problem is my navigation what i have on the left side is dynamic, and i can't assign module per page... – Nicky R. Oct 22 '13 at 22:25
  • @Lodder I think you are also required to `jimport` the `JModuleHelper`, or am I wrong? – mavrosxristoforos Oct 23 '13 at 05:25