2

I got stuck. I'm coding a simple module which will be placed/visible only on com_content article pages. This module fetches keywords from the current article, and to avoid an additional database query I use JDocument/getMetaData:

$item = JFactory::getDocument();
$item_keywords = $item->getMetaData('keywords');

This code works well when the module is placed in regular module position and I'm able to get the list of keywords:

architecture, design studio, house

But when I inserted the module in article content through the {loadposition} plugin, I found out that the module cannot retrieve keywords from the current article using JDocument/getMetaData.

Is there any solution how I can retrieve article keywords in the module without additional database query?

Probably I'll add a a code that checks how the module is loaded. My code:

$item = JFactory::getDocument();
if ($item->template) {
    echo "standart module load - use getMetaData";
} else {
    echo "module loaded by plugin - create an additional query";
}

Do you have a better idea?

2 Answers 2

1

You can't use standard Joomla {loadposition} content plugin for this purpose because content preparation occurs much before head data preparations.

You will need to write your own Joomla System plugin for the replacement like NoNumber's Module Anywhere plugin which replaces the mos code with the module after head data preparation. To learn more refer to the list of Joomla Plugin events: https://docs.joomla.org/Plugin/Events

2
  • Thank you. You clarified the sequence of data preparations. I cannot control how the module will be used, users can place it in ordinary module position or use core Joomla loadmodule plugin. Right now I see this solution. Make a check how the module is loaded, and if it's done through plugin, make an additional query to get keywords. I've updated my question above.
    – Beshur
    Commented Sep 18, 2015 at 19:30
  • Yes, I could assume that and that's why I suggested you you support your module by your own system plugin which you can provide with your module. It should not be tough to design such plugin. If you need I can also help you with the plugin codes. Let me know.
    – Jumbo
    Commented Sep 18, 2015 at 19:35
0

It's probably easiest to fetch the keywords manually with sql from your module. Something like (if view=article):

$app=JFactory::getApplication(); 
$id = $app->input->getInt('id', 0); 
$db=JFactory::getDbo(); 
$db->setQuery("select metakey from #__content where id={$id}");
$keywords=$db->loadResult(); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.