Creating a Multi-View Joomla Template

I have nearly completed my new portfolio site. I built it using Flash and Joomla. I created a Flash application to display the actual portfolio (thumbnails, links, etc). I then created a Joomla component and module (gsPortfolio) that incorporates the Flash portfolio application.

When I created the Joomla template for my site, I designed it specifically for the display my portfolio. Unfortunately, this layout was not generic enough to accommodate secondary pages (my portfolio is displayed on the home page). After looking at the code of the JA_Purity template, I was able to figure out how to create multiple views in a single template.

Note: Although with Joomla, you can select a different template for any page, my goal was to have different layouts incorporated into the same template – A layout for the front page and a layout for the secondary pages.

The Views

First I created a folder under my template folder named views (templates/myportfolio/views). I create two files under the views folder (frontpage.php and main.php). I created the frontpage.php file by copying everything that was in the index.php file (remember, my portfolio is contained on my home page). The main.php file contains the layout for all other pages for my site.

The Index.php File

I then changed the index.php file into a controller. I actually created a php class, but I will simplify the code for the purposes of this post.

<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
function isFrontPage(){
	return (JRequest::getCmd( 'view' ) == 'frontpage') ;
if (isFrontPage()) {
	include_once (dirname(__FILE__).DS.'/views/frontpage.php');
} else {
	include_once (dirname(__FILE__).DS.'/views/main.php');

I borrowed the isFrontPage function from the JA_Purity template. If the page displayed is the home page, then include the file /views/frontpage.php, else include the file /views/main.php.

The CSS Files

I created three css files. A file that is shared by all pages and styles that are specific by to each page. I include these files within each view. For instance, in the frontpage.php file:

<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/css/styles_all.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template?>/css/styles_front.css" type="text/css" />

That’s it. Fairly simple. Now I have multiple views in one Joomla template. Enjoy.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks