08
Jul
Adding variable request in helloworld or any joomla module
- Category:
- Joomla
Posted On : July 8, 2013
| 1 Comment
In this Joomla Module Tutorial you will find how to add variable request in module. Adding a variable request to a module is simple which is done by installation file .xml. We will replace some code in the xml file to add variable request in the Helloworld Module.
Creating Variable Request
In the .xml file we will add <config> tag to add variable request like shown below.
1 2 3 4 5 | <fieldset></fieldset> tag contains the name attribute which will be used in the php file to access the variable. <fieldset> tag groups the variable request under ‘name’ attribute. tag contains the variable request with various attribute such as name of the variable,type of the variable, default value of the variable, label shown in the module and description shown on mouse hover. Here we have created two variable request with name width and height.</fieldset> |
Accessing Variable Request
A variable defined above have to be accessed in the mod_helloword.php file. It is done by the get() function.
1 2 3 4 | $width = $params->get('width'); $height = $params->get('height'); where, $params is the tag name defined in .xml file. |
tag name defined in .xml file.
Replacing default.php File
This file contains the output to be displayed by the module. This file has the same scope as that of the mod_helloworld.php. So the variables defined in mod_helloworld.php can be directly accessed in this file. ‘$hello’ variable defined in mod_helloworld.php can be directly accessed here.
The complete code of tmpl\default.php is given below.
1 2 3 4 5 6 7 | <!--?php // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); ?--> <!--?php echo $hello; ?--> width = <!--?php echo $width; ?--> height = <!--?php echo $height; ?--> |
SCREENSHOT
User View
- Tags:
Posts
Heya i am for the first time here. I came across this blog and I found It truly helpful & it helped me out a lot.
Maryann