Joomla Template Parameter in PHP

Introduction

In this article, I am describing how to use template parameters in Joomla. We will use a Joomla 1.5 template. This articles covers only templates, so it's assumed that I already have a Joomla 1.5 website installed. This is a quick article about the use of a Template Parameter in Joomla. You can change the functionality of a template with the use of template parameters that you can set from an admin panel. Parameters are an excellent way to make your template more flexible. In the Admin panel, default templates are included in the system and can use them. By adding code into the template file, you can retrieve the current value of the parameter. In Joomla, we can configure component display functionality from the template file using the "Get" method in index.php.

Template Parameter

In Joomla! the template parameters are defined in the templateDetails.xml file. Whereas in 1.5 the parameters are defined as parts of the <params> section in Joomla, and each parameter is defined as a <params>, template parameters are contained in the <config> section and treated as a <field> nested within the <fieldset> and <fields> tags, as illustrated here.

<config>

    <fields name="params">

        <fieldset name="basic">

            <field name="" type="" default="" label="" description="">

                <option value="1">On</option>

                <option value="0">Off</option>

            </field>

            <field name="" type="" default="" label="e" description="" />

        </fieldset>

    </fields>

</config>

The fieldset tag (that sets the "name" attribute to "basic") wraps the parameters in a grouping element. Using name="basic" labels that element as "Basic Options" and name="advanced" labels it as "Advanced Options". Retrieve template parameters using code such as in the following:

<?php

$this-&gt;params-&gt;get('paramName');

?>


"Params" basically can be used for get and set parameters. This is accessible for global scope. This object to the member function get() returns the parameter value given the name. Let's have a look at an example for the template parameter.

TemplateDetailes.xml

You will add a templateDetails.xml file by using this code.

NoYes

You will use a templateDetails.xml file that can contain template parameters so we can change the template. 

Params.ini

Next, store the parameter in the params.ini file.

showTopbutton=1

Template File

The Template Parameters access the from in a template using the code such as:

<?php

 

if ($this-&gt;params-&gt;get('showTopbutton') == "true")

    {

      // Desire code to load top button

    }

?>

 Tamplate-in-joomla.jpg


Similar Articles