ThemePartner, Professional Joomla! Business Templates

Theo

Get Joomla! 1.7 Plugin, Module, Component and Template Parameters

August 19th, 2011 at 7:45 PM CEST in Technical

A little under a year ago I wrote a blog post on how to 'Retrieve Plugin, Module, Component and Template Parameters in Joomla! 1.5'. At this moment, that blog is in our top 10 of most read blogs! Given this popularity and the number of comments that short blog received, it made sense to write a new version with information on how to get these parameters in Joomla! 1.7.

Parameter

Image credits: edwin_young

Plugin parameters from inside a plugin

$param = $this->params->get('paramName', defaultValue);

Plugin parameters from outside a plugin

$plugin = JPluginHelper::getPlugin('editors', 'codemirror');
$pluginParams = new JRegistry();
$pluginParams->loadString($plugin->params);
$param = $pluginParams->get('paramName', 'defaultValue');

Module parameters from inside a module

$param = $params->get('paramName', 'defaultValue');

Module parameters from outside a module

$module = JModuleHelper::getModule('banners');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
$param = $moduleParams->get('paramName', 'defaultValue');

Component parameters from inside a component

$app = JFactory::getApplication('site');
$componentParams = $app->getParams('com_content');
$param = $componentParams->get('paramName', defaultValue);

Component parameters from outside a component

$app = JFactory::getApplication('site');
$componentParams = $app->getParams('com_example');
$param = $componentParams->get('paramName', defaultValue);

Template parameters from inside a template

$param = $this->params->get('paramName', defaultValue);

Template parameters from outside a template

$app = JFactory::getApplication('site');
$template = $app->getTemplate(true);
$param = $template->params->get('paramName', defaultValue);

Thanks to Peter for pointing this one out in the comments!

Follow us on Twitter

User Comments (19)

Add comment

Joomla CMS

August 23rd, 2011 at 12:53 PM CEST
Hi! Am a beginner to Joomla. Although my comment might not be related to your blog but I would like to know that does the Joomla basic version makes the key to new versions or should I start from the latest version only.

Theo

August 23rd, 2011 at 1:03 PM CEST
In most cases it is adviced to start with the latest version if you're developing a new website.

joomla CMS

September 2nd, 2011 at 2:53 PM CEST
I also agree with Theo as you should start with the latest version.It will help you to make a new website.

oksida.com

September 3rd, 2011 at 4:57 AM CEST
thanks.. i'm looking for this

Peter

September 14th, 2011 at 1:47 AM CEST
I'm extremely keen to know how to retrieve
"Template parameters from OUTside a template"
e.g.:
- in a component?
- or in offline.php (from my template)

Thx.

Theo

September 15th, 2011 at 3:31 PM CEST
Hi Peter,

So far we haven't been able to retrieve the information you've requested in a clean way either. If anybody else has, please post it in a comment below and I'll add it to the blog with your credits.

Regards,
Theo

Peter

September 21st, 2011 at 1:37 PM CEST
Hi Theo,

To be franky: I've found a way which (actually) works from everywhere. What I don't really know: how secure and safe this code.
I'm using this one (using the advantage of that J1.7 stores the template params in the DB):

$app = JFactory::getApplication();
$template = $app->getTemplate(true);
$param = $template->params->get('<param_name>', '<def_value>');

Regards,

Peter

Peter

September 21st, 2011 at 1:39 PM CEST
Aye. The trick is in the above code:
getTemplate(true) - this creates the template instance (if not exist).

Without the 'true' option you don't get the template object itself, but only its name (also a string).

Peter

Theo

September 21st, 2011 at 4:22 PM CEST
Hi Peter,

Awesome! You've found a way!

Apparently the getTemplate() function is actually documented here (http://docs.joomla.org/JApplication::getTemplate/1.6) and the usage you've proposed therefore seems secure and safe to me.

I just added your code to the main blog, with credits to you.

Thanks!

Regards,
Theo

Peter

September 21st, 2011 at 5:05 PM CEST
You are welcome, Theo.

My last advice would, if you refering the API docs, may be better to use the Joomla Platform related links (which is built into Joomla more and more deeply), rather than the J1.6 version related links.

I've found already some (minor and major) differences between the Platform and J1.6 docs. And as it seems to me, there will be more differences in the future.

My only headache with J17 and JPlatform: the guys with the documentation are way behind the code :(

Here is the correct link to getTemplate in J1.7:
http://docs.joomla.org/JApplication::getTemplate/11.1

Ciao.

Peter

Sandra

October 17th, 2011 at 2:06 PM CEST
Hi Theo,

I think I need the above solution for my site.
Could you please tell me where exactly I need to place the above php code?

(I want the component parameters back into my menu items just like in Joomla 1.5)

Theo

October 17th, 2011 at 2:59 PM CEST
Hi Sandra,

Implementing the solution you've requested isn't something that you can just do in a couple of minutes. If you can't make these changes yourself, I'd suggest you contact a local Joomla developer that can build this custom solution for you.

Good luck!

Regards,
Theo

C.N.

October 22nd, 2011 at 4:57 AM CEST
Thank you for this!

I'm converting a module from 1.5 to 1.7. I've been struggling with the "helper" files and the "outside a module" code works perfectly for an AJAX handler.

Cheers!

Morten

November 1st, 2011 at 9:35 PM CET
Nice! Was looking for a way to retrieve template parameters from a module. Thank you so much for this.

Trikks

November 4th, 2011 at 2:29 PM CET
Hi

you might want to include which files and libraries to include in an external file to actually make this happend.

Thanks

urgent

December 12th, 2011 at 10:32 PM CET
I am using rockettheme and $params->get("layout_type", "layout1") keep returning layout2 where it is no where declared within the module xml to be layout2 and even when the file is complete removed will still return layout2. I would like to know where it's getting the false value from and why

sasi varna kumar

January 6th, 2012 at 11:50 AM CET
Thank you man, thats a good job,
i wasted some time in searching for this piece of code.

Lakshmi Kanta Patir

March 6th, 2012 at 8:17 AM CET
This is awesome. Concise but very useful. Look forward for more such tutorials. Thank You.

Umer

April 8th, 2012 at 6:51 PM CEST
Hi,

thank you very much for all the informations.

I have a problem/question and hope someone can help me.

I´m using CommunityBuilder and do have a special fiels (Special-ID) and I need to retrieve/get that "Special-ID".
How can I get this done?

If you need any further information, please don´t hesitate to ask me.

Thanks in advance for any help.

Greetings,
Umer

Add a comment

*
*
*

*

 

Buy 2 Templates, Get Your Third Free!

Buy 2 Templates, Get Your Third Free!

By popular demand we've introduced a way to purchase multiple templates, at a discounted rate! If you add any three templates to your shopping cart, you'll only have to pay for two!

Blog categories

Conferences

Upcoming conferences

Past conferences

Reports on past conferences