Joomla! with Flash: Flashy Templates, Headers, Banners, and Tickers: Part 1

Exclusive offer: get 50% off this eBook here
Joomla! with Flash

Joomla! with Flash — Save 50%

Build a stunning, content-rich, and interactive web site with Joomla! 1.5 and Flash CS4

$23.99    $12.00
by Suhreed Sarkar | November 2009 | Joomla! Content Management Open Source PHP

In this two-part article by Suhreed Sarkar, we are going to use Flash for decorating our Joomla! site. On completion of this article you will be able to use:

  • Flash-based templates for your Joomla! website
  • Flash logos
  • Flash headers
  • Flash banners

In this article, we will mainly focus on the visual design of our site. To acquire the information presented here, it is assumed that you have some basic understanding of Joomla!'s visual design including templates, components, module position, and so on.

Adding Flash in templates

If you are familiar with Joomla! templates, then you will understand that there are two ways to display Flash in a template:

  • By hardcoded embedding of Flash items
  • By dynamically loading Flash objects at module positions

We have seen many modules that can display Flash objects. Therefore, in this section, we will be looking into the embedding of Flash objects within templates. It will also be helpful if we understand the structure of Joomla! templates.

Generally templates for Joomla! include headers in Flash. Flash animations are included in the header area of a Joomla! template. Some templates include the mechanism to show images from a specific directory. For example, the template shown in the following screenshot, available for download at http://joomlatp.com/joomla-1.5-templates/Templates-has-flash-header.html, is designed to show a Flash header comprised of the images kept in a directory:

Joomla! with Flash

The following sections briefly describe the structure of a Joomla! template and the ways to embed a Flash object in this template.

Structure of a Joomla! template

The look and feel of Joomla! is determined by templates. You can apply a template to the frontend as well as to the backend. Templates for the Joomla! frontend reside in the /templates directory of the Joomla! webroot, while those for the administration panel are found in the /administrator/templates directory. You can install multiple templates and apply one or more templates to the different sections. However, you must designate one default template for the site.

To designate a default template, go to Extensions | Template Manager. Select the desired template and click on the Default button on the toolbar. For assigning a template to a specific section of the site, click on a template, except the default template, and then select the section or the menu item for which you want to assign the template from the Menu Assignment section.

If you examine the directory structure of a Joomla! template, you will find at least the following subdirectories in the templates directory:

Directory

Description

mx_joofree2

This is the main template directory. It contains some subdirectories and at least the following files under its root:

  • index.php: This is the main file for a template. The basic structure of a Joomla! template is defined in this file. We will examine this file later.
  • templateDetails.xml: This XML file defines the template by mentioning its designer, the different files bundled with it, the positions and parameters available, and so on.
  • params.ini: This file contains the parameters and their default values. For example, a template may use several colors for theming, but users can select a preferred color as a parameter for this template, and that information is stored in this file.

mx_joofree2/css

This directory contains all the cascading stylesheets to be used for a Joomla! site. This directory will contain at least one stylesheet named template_css.css. It may also contain a stylesheet named template_ie6.css and other stylesheets.

mx_joofree2/html

This folder may contain some definitions for the custom rendering of certain parts of the site. For example, the mx_joofree2 template contains two files-module.php and pagination.php. These two files define custom module rendering and pagination for Joomla!. For more information on using HTML overrides, refer to http://docs.joomla.org/How_to_override_the_content_from_the_Joomla!_core.

mx_joofree2/images

This folder contains the images for the template. It may contain a logo image, a background image, and so on. It may also contain some subdirectories, for example, the mx_joofree2 template contains a subdirectory images/headers, where the header images for the template are stored.

Joomla! with Flash Build a stunning, content-rich, and interactive web site with Joomla! 1.5 and Flash CS4
Published: October 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

As you know, the main structure of a Joomla! template is defined in the index.php file. The file looks as follows:

<?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted index access' );

This line of code is to prevent direct access to the file. This is a convention to prevent direct access to any file in Joomla!. After this, the following lines define some variables for the template that will be used later on in the template:

define( 'YOURBASEPATH', dirname(__FILE__) ); 
$live_site = $mainframe->getCfg('live_site');
$template_path = $this->baseurl . '/templates/' . $this->template;
$show_flashheader = ($this->params->get("showFlashheader", 1) == 0)?"false":"true";
$show_logo = ($this->params->get("showLogo", 1) == 0)?"false":"true";
$show_date = ($this->params->get("showDate", 1) == 0)?"false":"true";
$show_breadcrumbs = ($this->params->get("showBreadcrumbs", 1) == 0)?"false":"true";
?>

Having defined the template variables, the template's structure starts with some common HTML declarations as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang=
"<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>

Whatever is included after the following lines will be considered as included in the <head> section. Generally, stylesheets, JavaScript, and site-wide files are included in a template's <head> section with the following lines:

<jdoc:include type="head" /> 
<link rel="shortcut icon" href=
"<?php echo $this->baseurl; ?>/images/ favicon.ico" />
<link href="<?php echo $this->baseurl ?>/templates/system/ css/system.css"
rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseurl ?>/templates/system/css/general. css"
rel="stylesheet" type="text/css" />
<link href="<?php echo $this->baseurl; ?>/templates/<?php echo $this->
template?>/css/template_css.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="templates/<?php echo $this->
template ?> /css/ie6.css" type="text/css" />
<![endif]-->
</head>

If you have read this article you may be interested to view :


Next, the body section of the template starts:

<body class="body_bg"> 
<div id="bgr">
<div id="wrapper">
<div id="tophead">

The following block checks whether any module for position user4 is enabled. If the count of enabled modules is greater than zero, then a <div>element with an ID search is displayed, and modules specified for position user4 are displayed as children of this <div> element:

<?php if($this->countModules('user4')) : ?> 
<div id="search">
<jdoc:include type="modules" name="user4" style="xhtml" />
</div>
<?php endif; ?>

Having placed the modules for the position user4, the following block now defines where to show the site's logo. This block of code dynamically selects the site's logo and links that to the site's home page:

<!-- BEGIN: LOGO --> 
<?php if($show_logo == "true") : ?>
<div id="logo">
<a href="<?php echo $mosConfig_live_site;?>">
<img src='//dgdsbygo8mp3h.cloudfront.net/sites/default/files/blank.gif' data-original="<?php echo $this->baseurl; ?>/templates/<?php echo $this->
template?>/images/logo.png" alt="" />
</a>
</div>
<?php endif; ?>
<!-- END: LOGO -->

If we want to show a Flash header beside the logo, then we can add the following block to include a Flash object:

<!-- BEGIN: flashheader --> 
<?php if($show_flashheader == "true") : ?>
<div id="ol-flashheader">
<object type="application/x-shockwave-flash" data="<?php echo $this->
baseurl; ?>/templates/<?php echo
$this->template?>/ images/header.swf " width="700" height="240">
<param name="wmode" value="transparent" />
<param name="movie" value="<?php echo $this->baseurl; ?>/templates/
<?php echo $this->template?>/images/header.swf" />
</object>
</div>
<?php endif; ?>
<!-- END: flashheader -->

This code block first checks whether the variable for showing a Flash header is checked or not. If it is checked, then a  <div> element will be created, under which the Flash object is embedded using the <object> </object> tags.

The following code block is used to display the current date on the site:

<!-- BEGIN: Date --> 
<?php if($show_date == "true") : ?>
<div id="date-format">
<?php $now = &JFactory::getDate(); echo $now->toFormat("%A, %d %b %Y"); ?>
</div>
<?php endif; ?>
<!-- END: Date -->
</div>

The following block defines another module position. Modules designated for the user3 position will be displayed here. Note that modules are included with the <jdoc:include type="modules" name="position-name" /> markup:

<?php if( $this->countModules('user3') ) {?> 
<div id="topcol">
<div id="topmenu">
<table cellspacing="0" cellpadding="0" style="float: left;">
<tr>
<td>
<jdoc:include type="modules" name="user3" />
</td>
</tr>
</table>
</div>
</div>
<?php } ?>
<div id="wrapper_2">
<div id="holder">

The following code block displays another module called breadcrumbs. First, it checks whether the parameter is set to show breadcrumbs or not. If it is, then the breadcrumbs module will be displayed in the block:

<!--pathway start--> 
<?php if ($show_breadcrumbs == "true") : ?>
<div class="path">
You are here: <jdoc:include type="module" name="breadcrumbs"/>
</div>
<?php endif; ?>
<!--pathway end-->

Next comes the module for the left position:

<div id="content"> 
<?php if($this->countModules('left') and
JRequest::getCmd('layout') != 'form') : ?>
<div id="left">
<jdoc:include type="modules" name="left" style="rounded" />
</div>
<?php endif; ?>

The following block includes the modules designated for the right position:

<?php if($this->countModules('right') and
JRequest::getCmd('layout') != 'form') : ?>
<div id="main">
<?php else: ?>
<div id="main_full">
<?php endif; ?>
<div class="nopad">
<jdoc:include type="message" />

The next code block counts the number of modules available for the user1 and user2 positions and then includes the modules designated for these two positions. Note the highlighted line of code in this code block. It shows the component currently selected:

<!-- BEGIN: USERS TEMPSPLASH --> 
<div id="lr-padd">
<table class="lr-padd" cellspacing="2">
<tr valign="top">
<?php if( $this->countModules('user1') ) {?>
<td class="lr-padd">
<jdoc:include type="modules" name="user2" style="xhtml" />
</td>
<?php } ?>
<?php if( $this->countModules('user1') ) {?>
<td class="lr-padd">
<jdoc:include type="modules" name="user2" style="xhtml" />
</td>
<?php } ?>
</tr>
</table>
</div>
<!-- END: USERS TEMPSPLASH -->
<jdoc:include type="component" />
</div>
</div>
<?php if($this->countModules('right') and
 JRequest::getCmd('layout') != 'form') : ?>
<div id="right">
<jdoc:include type="modules" name="right" style="rounded" />
</div>
<?php endif; ?>
<div class="clr"></div>
</div>
</div>

Finally, here comes the footer section. The highlighted line in the following code block includes a footer file to show the footer text:

<!--footer start--> 
<div id="footer">
<div id="footer_in">
<div>
<div style="text-align: center; padding: 18px 0 0;">
<?php include (dirname(__FILE__).DS.'/footer.php');?>
</div>
</div>
</div>
</div>
<!--footer end-->
</div>
</div>
</div>
</div>
<jdoc:include type="modules" name="debug" />
</body>
</html>

All this code in the index.php file when rendered with template_css.css and other stylesheets will display a layout like the one shown in the following screenshot:

Joomla! with Flash

In a Joomla! template, the site's data comes from the database and fits in different positions. When you are planning for Flash-based Joomla! templates, you should first identify where to put the Flash objects and where to display the dynamic data for the site. In the template layout, we have seen that a suitable place for adding a Flash object are the logo and the header positions. We can also use some extensions to display Flash headers. The following sections explain how to use extensions for showing Flash logos and headers.

Using Flash logos

You can replace the ordinary image with Flash-animated logos by embedding it in that position. As we have seen earlier, Flash objects are embedded in Joomla! templates using the <object> </object>XHTML element. For styling purposes, you may put this element under a <div> element, as shown in the following code:

<div id="logo"> 
<object type="application/x-shockwave-flash" data=
"/templates/mx_joofree2/images/logo.swf" width="200" height="200">
<param name="movie" value="/templates/mx_joofree2/images/logo.swf">
</object>
</div>

As you can see, the <object> </object> tag can contain child elements. We pass parameters to the Flash objects using the <param> element. For example, we have passed the name of a movie file using the highlighted tag in the previous code.

Some of you may already know about the SWFObject JavaScript library. It is used to embed Flash files using JavaScript. You can also use it to embed Flash objects in Joomla! and can also generate Flash objects. It is freely available at http://code.google.com/p/swfobject/. Brief documentation on its usage is also available there.

>> Continue Reading: Joomla! with Flash—Flashy Templates, Headers, Banners, and Tickers: Part2


If you have read this article you may be interested to view :


Joomla! with Flash Build a stunning, content-rich, and interactive web site with Joomla! 1.5 and Flash CS4
Published: October 2009
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

About the Author :


Suhreed Sarkar

Suhreed Sarkar is an IT consultant, trainer and technical writer. He studied Marine engineering, served on board the ship for two years, and then started journey in to IT world with MCSE in Windows NT 4.0 track. Later he studied business administration and earned MBA from University of Dhaka. He has a bunch of BrainBench certifications on various topics including PHP4, Project Management, RDBMS Concepts, E-commerce, Web Server Administration, Internet Security, Training Development, Training Delivery and Evaluation, and Technical Writing.

He taught courses on system administration, web development, e-commerce and MIS. He has consulted several national and international organizations including United Nations, and helped clients building and adopting their web portals, large scale databases and management information systems. At present he is working on building a framework for education sector MIS, and promoting use of ICTs in education.

Suhreed is renowned technical author in Bengali – having a dozen of books published on subjects covering web development, LAMP, networking, and system administration. He authored Zen Cart: E-commerce Application Development, Joomla! E-commerce with Virtuemart, and Joomla! with Flash, published by Packt Publishing.

While not busy with hacking some apps, blogging on his blog (http://www.suhreedsarkar.com), reading philosophy of Bertrand Russell or management thought of Peter F Drucker – he likes to spend some special moments with his family. Suhreed lives in Dhaka, Bangladesh

Contact Suhreed Sarkar

Books From Packt


Joomla! 1.5x Customization: Make Your Site Adapt to Your Needs
Joomla! 1.5x Customization: Make Your Site Adapt to Your Needs

Joomla! 1.5 Development Cookbook
Joomla! 1.5 Development Cookbook

Joomla! 1.5 Content Administration
Joomla! 1.5 Content Administration

Joomla! 1.5 SEO
Joomla! 1.5 SEO

PHP Team Development
PHP Team Development

jQuery 1.3 with PHP
jQuery 1.3 with PHP

Ext JS 3.0 Cookbook
Ext JS 3.0 Cookbook

Plone 3 for Education
Plone 3 for Education


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3
S
Z
1
q
T
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software