Keyword

Module Position in K2 Template

  • WebHelpUS
  • WebHelpUS's Avatar Topic Author
  • Offline
  • Senior Member
More
6 years 5 months ago #165049 by WebHelpUS
Module Position in K2 Template was created by WebHelpUS
Can you add module positions to a K2 template?

Please Log in or Create an account to join the conversation.

More
6 years 5 months ago #165054 by william white
Replied by william white on topic Module Position in K2 Template
I dont think this will work because it will probably confuse some process but see here:
docs.joomla.org/Declaring_module_positions
Add a position in the template xml file
add the include statement into the override
assign a module to the position
test it

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 5 months ago #165091 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module Position in K2 Template
Yes, you can the same way you would modules outside of Joomla!'s index.php file using Joomla!'s module helper. You need to consult Joomla!'s API for this.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • Ronny Van Der Borght
  • Ronny Van Der Borght's Avatar
  • Offline
  • Senior Member
More
6 years 5 months ago #165094 by Ronny Van Der Borght
Replied by Ronny Van Der Borght on topic Module Position in K2 Template
I do this all the time, in fact it gives you the ability to have real template variations depending on k2 categories.
This is how it's done:
<?php
// get document
$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer( 'modules' );
$style = array( 'style' => 'raw' ); // you can change raw to other styles

if ($doc->countModules('sidebar') > 0) {
echo $renderer->render('sidebar', $style, null);
}
?>

Where 'sidebar' is the module position's name.

Please Log in or Create an account to join the conversation.

More
6 years 5 months ago #165095 by Nadal Kumar
Replied by Nadal Kumar on topic Module Position in K2 Template
It's much simpler to use JHTML with content.prepare then implement the core loadposition plugin.
A simple one liner placed anywhere in item.php
<?php echo JHtml::_('content.prepare', '{loadposition k2pages,xhtml}'); ?>

If using earlier Joomla versions (2.5.x and below), you will need to import the plugin helper class
<?php JPluginHelper::importPlugin('content');
echo JHtml::_('content.prepare', '{loadposition k2pages,xhtml}'); ?>

Then any module added to position k2pages will render in the K2 template. This method is applicable in any content display file, so it can be used in category view.

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 5 months ago #165210 by Krikor Boghossian
Replied by Krikor Boghossian on topic Module Position in K2 Template
Sorry to burst in, as Nadal explais, this is the optimal solution but remember to use overrides (if you are not already doing so)
getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum