Basic parameter types in a Joomla 2.5 plugin

Joomla 2.5 has reached its end of life as for 12/31/2014. Please be advised this may be a security risk to your website. You can view more information about the end of life here.

When adding parameters to Joomla 2.5 plugins, there are various input types you can use. In our testing thus far, we have only used the text input type. In this Joomla 2.5 tutorial, we’ll cover some of the various other plugin parameter types that you can use.

Radio type plugin parameters

setting-up-a-radio-parameter

Example Code:

<field name="color" type="radio" default="black" description="Which color should the message be displayed in?" label="Color">
    <option value="black">black</option>
    <option value="red">red</option>
    <option value="blue">blue</option>
</field>

The code to add a radio button as a plugin parameter is very similar to the standard code for using radio buttons in HTML.

Accessing the value of a radio button within your plugin’s php file is similar to getting the value of a standard text type field. As our field’s name above is color, we’ll get the value of the user’s color using that name, as in:

$this->params->get(‘color’)

List type plugin parameters

adding-a-list-plugin

A list parameter refers to a drop down list. In our hello world plugin, we added the following list to allow users to choose what font size they would like the message displayed using.

Example Code:

<field name="font-size" type="list" default="12" description="What size font should the message use?" label="Font size">
    <option value="8">8px</option>
    <option value="12">12px</option>
    <option value="16">16px</option>
</field>

Again, accessing the parameter value itself is done in the same manner:

$this->params->get(‘font-size’)

Text parameter input type

standard-text-type-input

To make this a well rounded tutorial, we’ll also include the text input type (even though we referenced it in a previous article).

Example Code:

<field name="alt-text" type="text" default="" label="Alternative Text" description="Besides Hello World, you can specify other text here to print to the screen instead." />

To access this value, again use the following code in your plugin’s php file:

$this->params->get(‘alt-text’)

0 thoughts on “Basic parameter types in a Joomla 2.5 plugin

  1. Sir, 

    Please tell how to update the php file with this code of  the radio type parameters and list type parameters.

Was this article helpful? Join the conversation!