Back to Top

When developing templates, especially those that are destined for a specific site, I often need to set the component include (which loads component content - the actual site articles etc) to disabled when on the site's home page.

This is really simple to do in Joomla 1.5, all it requires is a small snippet of PHP added to the template's index.php file, and you will have a variable which you can use to test, allowing simple includes/omissions or more complex techniques such as alternative template layouts.

Creating the Test

Open up the HTML (index.php) for editing in Joomla's Template Manager, and in the <head> region, simply add the following lines of code:

<?php 
$home = 0;
$menuitem = & JSite::getMenu();
if ($menuitem->getActive() == $menuitem->getDefault()) {
$home = "1";
}
?>

This simply sets a true-or-false state on the variable $home depending on whether the current (active) menu link is the same as the default (front page) link. Simple!

When you need to test the condition, simply do this:

<?php if ($home) : ?>
// DO SOMETHING
<?php endif; ?>

Or, if you need to test the opposite (if the user is not on the front-page):

<?php if (!$home) : ?>
// DO SOMETHING
<?php endif; ?>

...and there you have it.  A nice, simple front page tester for your templates.