phpeveryday.com

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


Joomla - Module: Using Template for Layout Flexibility (Part 6)

Tag: joomla, cms   Category: PHP Framework
post: 21 Nov 2007 read: 2,039


In this tutorial, we try to build template system for our module. Template is something that produce output to browser. We will exclude all output in mod_hello and put it to layout file.

First, change code mod_hello like following code:


<?php
defined('_JEXEC') or die('Restricted access');
require(dirname(__FILE__).DS.'helper.php');

$rows = modHelloHelper::getHello($params);
foreach($rows as $row)
{
   	modHelloHelper::renderHello($row, $params);
}
?>

What's that mean? We don't use echo again at this line code. Because, output will put at renderHello (in modHelloHelper class). Ok, now we go to helper.php. Change renderHello with following code:


	function renderHello(&$hello, &$params)
	{
		$link = JRoute::_('index.php?option=com_hello&id='.$hello->id.'&task=view');
		require(JModuleHelper::getLayoutPath('mod_hello' , '_hello'));
       }

We don't use return $link anymore because mod_hello.php doesn't have output. Now, we use layout. This layout at file named "_hello.php".

create folder named "tmpl" within joomla/modules/mod_hello. Then, create file name "_hello.php" within joomla/modules/mod_hello/tmpl. Enter following code:


<?php 
defined('_JEXEC') or die('Restricted access'); 
echo 'ID: <A href="'. $link .'">'.$hello->id.'</A> </br>';

 ?>

You have template at your module.



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