Coda Clips For Creating Joomla 1.5 Templates

This post is for all of you Mac fans out there, specifically those using the excellent Coda editor by Panic. I could preach all day long about how using a quality code editor like Coda can both speed up your coding as well as make your coding better.

One brilliant little function of Coda is that it has a built-in code snippet collector called 'Clips'. What's even more brilliant is that Coda gives developers a way to share groups of these clips with each other. I was inspired by our friend Jon from Zuno Studios when he released a few clip groups relating to Joomla 1.5 development a few months ago. His clips are specifically geared towards developers creating extensions, and if you're at that level I highly recommend checking out his handy clips.

Since more of my day-to-day work involves creating templates, I put together a set of clips that I use almost daily for creating Joomla 1.5 templates. Lucky for you Coda users out there, I've packaged them up in a tidy group that you can download.

Download Joomla Template Clips

To install, simply unzip the file and double-click on "Joomla Temmplates.clips". Or if you want to do it the manual way, open Coda, open your clips panel, right click in the left column and choose 'Import Group'.

Not a Coda User?

If you have yet to jump on the Coda bandwagon, it's okay. Here are each of the code snippets in the Joomla Template Clips.

Detecting Frontpage

<?php 
if ( JRequest::getVar('view') == 'frontpage' ) {
?>
<!-- display your home page HTML here -->
<?php
} else {
?>
<!-- display your internal page HTML here -->
<?php } ?>

Detecting Logged In State

<?php
$userattr = JFactory::getUser();
$thisuser = $userattr ->get('guest');
if($thisuser == 0) { ?>   // is this a guest user?
   //yes. do guest user stuff
<?php } else { ?>
   //no. do logged-in user stuff
<?php } ?> 

Load Component / Error

<?php if ($this->getBuffer('message')) : ?>
	

Message

<?php endif; ?>

Load One Module Position

<?php if ($this->countModules('user1')) : ?>
<?php endif; ?>

Load Four Module Positions

<?php if ($this->countModules('user1 or user2 or user3 or user4')) : ?>
<?php if ($this->countModules('user1')) : ?>
<!-- end user1 --> <?php endif; ?> <?php if ($this->countModules('user2')) : ?>
<!-- end user2 --> <?php endif; ?> <?php if ($this->countModules('user3')) : ?>
<!-- end user4 --> <?php endif; ?> <?php if ($this->countModules('user4')) : ?>
<!-- end user5 --> <?php endif; ?>
<?php endif; ?>

3-Column Class Conditionals

//Put in Head section

	<?php 
	if($this->countModules('left and right') == 0) $contentwidth = "full";
	if($this->countModules('left or right') == 1) $contentwidth = "single";
	if($this->countModules('left and right') == 1) $contentwidth = "both";
	?>

//Then put in Body

//Then put in CSS #middleCol.full {width: 100%;} #middleCol.both {float: left; width: 50%;} #middleCol.single {float: left; width: 75%;}

Blank Index.html

<html><body bgcolor="#FFFFFF"></body></html>

No Direct Access

// no direct access
defined('_JEXEC') or die('Restricted access');

Basic HEAD Tag

<?php echo '<?xml version="1.0" encoding="utf-8"?' .'>'; ?>

<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>" >

<head>
	<jdoc:include type="head" />
	<?php JHTML::_('behavior.mootools'); ?>
	<meta name="mssmarttagspreventparsing" content="true" />
	<meta http-equiv="imagetoolbar" content="no" />
	<link rel="shortcut icon" href="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/favicon.ico" type="image/x-icon" />
	<link href="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" rel="stylesheet" type="text/css" media="screen" />
	<script src="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/template.js" type="text/javascript">
	
	<!--[if lte IE 6]>
		<link rel="stylesheet" type="text/css" href="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ie6.css" media="screen, projection" />
	<![endif]-->	
	<!--[if IE 7]>
		<link rel="stylesheet" type="text/css" href="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ie7.css" media="screen, projection" />
	<![endif]-->

</head>

Breadcrumbs Module