Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you test if you're on the homepage in Joomla?

Tags:

php

joomla

I'm working on a Joomla site, and I need the front page to look slightly different from the rest of the pages, but not enough to warrant the use of two themes (it's a pain to have to update two stylesheets and two sets of images every time I want to make a small change).

My thoughts are to throw in a little test in the index.php of the template: if we're at the homepage, serve X, otherwise, serve Y. However, I'm not entirely sure how to test this. I can't just use the URL because url.com/ and url.com/index.php and url.com/index.php? etc etc are all valid.

Does anyone know of a way to do what I'm trying to do? Like a $_JOOMLA['page'] variable or something convenient like that?

Thanks! --Mala

like image 605
Mala Avatar asked Nov 18 '09 20:11

Mala


2 Answers

if(JRequest::getVar('view') == "frontpage" ) {
    //You are in!
}
else {
    //You are out!
}
like image 93
Soufiane Hassou Avatar answered Nov 17 '22 22:11

Soufiane Hassou


To be shure that client is on homepage, you should test "is current page (Itemid) choosen as default menu item" like this code do (for Joomla 1.6, 1.7 and 2.5):

<?php
$menu = JFactory::getApplication()->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
    echo 'This is the front page';
}
?>

To find code for Joomla 1.5, look to http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page

like image 7
Stanislav Gamayunov Avatar answered Nov 17 '22 20:11

Stanislav Gamayunov