Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Dynamic Module Parameter

Dynamic Module Parameter

Using J!1.5.23 with native and K2 content.
The question is can I use MM or MMP to query the category of the currently displayed component content and use the value to dynamically filter a module's results.

Instead of creating a duplicate Most Popular module for each category that is filtered to that category and then having MM select the appropriate copy, could one module be used and have it's filter changed each time it's rendered to match it's context?

I have 100+ categories and four modules that need to have their parameters match their category so using 4 instead of 400 modules is very attractive.
Thanks for suggestions.

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Hi Duke,

yes, this is likely to be possible. Just need to get a few details sorted out:

1 - is the module to go on "category" pages, or on "item" pages (depending on the category of the item)?

2 - does the "Most Popular" module have a parameter in it that allows you to filter by category? I.e. when you create one of these and edit it, is there a dropdown or text field in there where you can choose which categories it should apply to?

3 - what actually is the module name that you're using for this? If you can point me in the right direction I can check it.

If there *is* a parameter for the category, then it should be easy to achieve using the Module Param Control feature of MetaMod: http://www.metamodpro.com/metamod/contr … parameters

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Hi Stephen -
Good news ... answers inserted ...

metamodguy wrote:

Hi Duke,

yes, this is likely to be possible. Just need to get a few details sorted out:

1 - is the module to go on "category" pages, or on "item" pages (depending on the category of the item)?
Both.  Ideally also any children thereof (subcategories and article/item views launched from the category/subcategory.) 

2 - does the "Most Popular" module have a parameter in it that allows you to filter by category? I.e. when you create one of these and edit it, is there a dropdown or text field in there where you can choose which categories it should apply to?
Yes - All modules I hope to do this with have a Basic Parameter (multiple-selection list)in which you can select a specific Category to filter to the samme as you can in Joomla core modules.  The objective is to set this parameter dynamically.  (I know you get the issue being solved - With 100 copies of the module you could link each of them to their respective 100 categories and associated menu items - a setup & maintenance nightmare - multiplied by the number of module variations on the page.) 

3 - what actually is the module name that you're using for this? If you can point me in the right direction I can check it.
For K2 Content, it's K2 Tools (built in) which can be configured to produce the K2 equivalent of Joomla's Most Recent / Most Popular / Latest modules. I believe K2 uses either catid or cid as the variable for category.  The other K2 module this would apply to is K2 User for the most prolific article contributors in the category.  I could also see it applying to the K2 extension of the Joomla Login to dynamically set the redirection URL using the category's alias.

If there *is* a parameter for the category, then it should be easy to achieve using the Module Param Control feature of MetaMod: http://www.metamodpro.com/metamod/contr … parameters

I believe this works parallel to Joomla's core modules / at least at first blush.  I'll read up on this link - thanks!!!!!!!!

I'll dig into it.

Cheers,
Stephen

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Hi,

I haven't got time for the full recipe just now, but I checked on the K2 module parameters and found that in the mod_k2_content module, the parameter that deals with the category selection is called "category_id".

If you want to set it to 1 category in particular you can do this:

$k2_mod = XXX; // replace XXX with the real id of the k2 module
$cat = YYY; // this would be pre-calculated and is the category id you want to show
$changes->mod($k2_mod)->setParam("category_id", $cat);
return $k2_mod;

If you want to set more than 1 category in the "category_id" parameter in the K2 content module, you have to separate them with a "|". e.g:

$changes->mod($k2_mod)->setParam("category_id", "23|56|$cat");


I'll put together some code to retrieve the cateogry id from the currently viewed item, tomorrow.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Excellent - I'll see what I can do with my limited skills.

Should the example be:
$changes->mod($k2_mod)->setParam("category_id", "23|56|".$cat);
(concatenate the literal string to the variable value)

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Yes, you can do it that way, but my way also works. If you use double-quotes for a string, you can put a $variable inside the double quotes and the variable gets expanded to its full value.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Is that a PHP thing (a/k/a feature) or is there a different Joomla function parsing process going on?  What keeps $ inside a string from being converted to something unexpected?  How do you keep a $ a $ when you truly want a literal - /$ or $$ (or is that a global) Sorry this is wandering Off Topic. 

Back on topic, any suggestions on syntax to query the current K2 category since menu id seems to attenuate once a read more link is clicked.  Even better, can a persistent variable be set that is active for all modules and menu links until a menu item selects a different category and thereby updates the variable  Would this be an appropriate approach to set context for many modules?  My PHP-foo is weak - need help with the basics for this context.  Thanks!

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Yes, that's a PHP feature.

If you don't want a variable to be parsed, then use single quotes instead of double quotes.

Alternatively you can put a "\" character in front of any character that you want to be taken literally. There are a number of other characters that get interpreted differently when the string is surrounded in double quotes. e.g. \n gets converted to a line break, \t to a tab, etc. So if you want to use a literal \ inside double quotes then you have to precede it with another \.

e.g.
echo "\\n"; //  this outputs:  \n
echo "\n"; // this outputs a line break character.
echo '\n'; // this outputs: \n

There are plenty of online resources available for learning PHP.

Back on topic: I'm not sure what you mean by "menu id seems to attenuate". Can you explain?

I don't think that setting a persistent variable (aka session variable) is going to be the best approach for your needs. It will be possible to calculate the category id for any given K2 article just based on the parameters passed from the URL.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

Thanks for the PHP tips/details.  Meanwhile, any luck on figuring out how to query the context for K2?  I'm still unable to pass a variable and have it impact anything.  Echoing $category_id produces a null in any context and setting it does not change how the module renders.  The only variable that seems to have values in Advanced debug is Itemid which reflects the current Menu Item.  If you are not able to look into this, please let me know so I'm not checking back day after day for results of efforts you mentioned you were going to try.  Don't take me wrong, I don't expect you to be solving my issues.  If MetaModPro can actually enhance K2, I think there's a lot of people using K2 that would adopt it.  I'd love your help breaking new ground but because I don't really understand how MM works under the hood, how it inserts itself into the middle of the module rendering process, I'm time pressed to go after other less elegant solutions that I can figure out how to implement.  Any assistance is appreciated.  Also, happy to throw some consulting fees at this instead of Donating when the site is done, if that's the issue.  Let me know if you can help.

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: Dynamic Module Parameter

One other thought -
drawing from your suggestion of using MMT to query for the category $alias to set a folder, is there a way to make the scope of $alias sufficiently broad that MMP can use it to set module context? 
MMT does the category alias query for all modules, and MMP does the alias to id conversion for each repository type.
Example - (except for the bug) MMT retrieves Category Alias value of 'selectedcategory' as value for $categoryalias
MMP wrapping Most Popular looks up the Joomla Category ID for the category with an alias of "selectedcategory".
MMP wrapping K2 Tools version of Most Popular looks up the Category ID for the K2 category that similarly has an alias of "selectedcategory".
MMP wrapping an image slider sets the images subfolder that's displayed to ..."/selectedcategory".
and so on for other modules that filter on a category.

Is this making any sense to have MMT feed context to MMP?
Thanks,
Duke

Duke
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
4
User Info:
 
Total Users:
4378
Newest User:
miller2341
Members Online:
0
Guests Online:
160

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked