phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - Module: Trying Alternative Layout (Part 7)

Tag: joomla, cms   Category:
post: 22 Nov 2007 read: 1,918


After trying template, in last tutorial, we will try to make different layout. It is proof that more efficient if we use this scenario. We can change layout without rewrite many code.

Example 1

Create "default.php" within joomla/modules/mod_hello/tmpl. Enter following code:


<?php 
defined('_JEXEC') or die('Restricted access'); 
 
foreach($rows as $row)
{
   	modHelloHelper::renderHello($row, $params);
}
 
?>

And then, modify "mod_hello.php" within joomla/modules/mod_hello. This modify will be implemented for all next example.


<?php
defined('_JEXEC') or die('Restricted access');
require(dirname(__FILE__).DS.'helper.php');
 
$rows = modHelloHelper::getHello($params);
require(JModuleHelper::getLayoutPath('mod_hello'));
?>

Example 2

Now, we want to add bullet in the list. So, create file named "bulleted.php" within joomla/modules/mod_hello/tmpl. Enter following code:


<?php 
defined('_JEXEC') or die('Restricted access'); 
echo "<ul>";
 
foreach($rows as $row)
{
   echo "<li>";
   	modHelloHelper::renderHello($row, $params);
   echo "</li>";
}
 
echo "</ul>";
 
?>

If we want to choose this layout, we just modify mod_hello become:


<?php
defined('_JEXEC') or die('Restricted access');
require(dirname(__FILE__).DS.'helper.php');
 
$rows = modHelloHelper::getHello($params);
require(JModuleHelper::getLayoutPath('mod_hello','bulleted'));
?>

Example 3

Now, we try show few text. Modify "_hello.php" within joomla/modules/mod_hello/tmpl.


<?php 
defined('_JEXEC') or die('Restricted access'); 

echo 'ID: <A href="'. $link .'">'.$hello->id.'</A> </br>';
echo $hello->message;

?>


Series this article:
Joomla - Module: Register Database (Part 1)
Joomla - Module: Showing Module at Front End (Part 2)
Joomla - Module: Show Items from database (Part 3)
Joomla - Module: Showing Few Text After Link (Part 4)
Joomla - Module: Using Helper (Part 5)
Joomla - Module: Using Template for Layout Flexibility (Part 6)
Joomla - Module: Trying Alternative Layout (Part 7)
Joomla - Component: Showing Number of Comment at Last Post (Part 8)

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting