0

If we have some list of items in category view of some component (no matter what component — interesting in general solution) how can we loop only the items with some condition that is given from some custom plugin but WITHOUT editing core files of the component or template overriding? For example we display the item titles of com_content through:

foreach ($this->items as $article)
{
 echo $article->title;
}

How can we "put" (not putting in com_content but programmatically on the fly) some condition from plg_myplugin to display only the items with this condition for example:

foreach ($this->items as $article)
{
  if($article->some_parameter == 'some value')
  {
     echo $article->title;
  }
}

In other words how to create own plugin-filter for sorting the items of component?

1

Currently none of common components has filter type plugins (at least non of core components). So there is no way to filter its content by plugin. For such functionality to work each component you want to have that filtering should include new event and and probably a whole new group of plugins should be added to system core. That is impossible without core modifications.

Small idea

Most of components use user state to get filtering default values for items view. Those can be modified using JSession (cause they are basically stored in JSession). Of course there are many problems like limited filtering options (only those that are prepared in getListQuery() and populateState() in items model of your component) or problem with overriding those values in component. But it is some sort of solution requires no changes in core and it is possible to do it in simple plugin (system type plugin will be the best for that).

0

You will need to utilize JModuleHelper and JRegistry to achieve this, like so:

$module         = JModuleHelper::getModule('mod_mymodule');
$moduleParams   = new JRegistry();
$moduleParams->loadString($module->params);

$parameter = $moduleParams->get('some_parameter');

foreach ($this->items as $i => $article)
{
    if ($parameter  == 'some value')
    {
        echo $article->title;
    }
}

In a Template Override of the category view, you won't need to use a loop, instead use something like the following:

if ($parameter  == 'some value')
{
    echo $article->title;
}
  • 1
    I think it is possible with a plugin, using maybe the onContentPrepare trigger, but this would be a lot more hassle and would require more code. I don't see why creating a small template or layout override can't be done as it's the simplest and most efficient method. – Lodder May 14 '15 at 10:14
  • Because I need an extension (module preferably) not a hack and one parameter is an example — there will be many parameters – stckvrw May 14 '15 at 10:15
  • It's not a hack. This is exactly what overrides are for ;). Maybe someone else will post a plugin based answer. In the mean time, maybe look at the current Joomla plugins and come up with something – Lodder May 14 '15 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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