Here is one quick article about to use Template Parameter in Joomla.You can change the functionality of template with the use of template parameters which you can set from admin panel.Parameters are an excellent way to make your template more flexible.
In 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 template file with using the get method.
In index.php, To retrieve template parameters by following line of code:
1 2 3 |
params can be used to get and set parameters.params is automatically accessible in the global scope. This object has the member function get() which returns the parameter value given the name
Let’s have a look one example for the template parameter.
Here, Let’s see whether you want to load Show Back to Top Button in the template file or not.You can add an option for same by placing code into params.ini,templateDetails.xml file and then you can retrieve a value in the template file.
Step 1: TemplateDetails.xml
First of all, Let’s add parameters into the templateDetails.XML file by using the following line of code.
1 2 3 | No Yes |
The templateDetails file can contain template parameters which can change the functionality of template. As Here, I have set that want to display MooTools library or not.
Step 2: Params.ini
Next, Lets stored the parameter in the file params.ini located in the folder of each template by adding following line of code into the params.ini file.
1 2 3 | showTopbutton=1 |
Step 3: Template File
Now, Parameters can be accessed from within the template by using code such as
1 2 3 4 5 | if ($this->params->get('showTopbutton') == "true") { // Desire code to load top button } |
Must Read:
Custom Query with Joomla
To disable component on front page in Joomla
To view Position in Joomla 2.5
That’s it.I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (2)