How do I getView() or tell If I am at the home page - SOLVED

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
jbdev
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Mar 05, 2007 3:36 pm

How do I getView() or tell If I am at the home page - SOLVED

Post by jbdev » Tue Aug 14, 2007 6:15 pm

so without checking $_GET(), how do I find out if I am on the home page? I need to have code execute only on home page... any ideas

Thank you 
Last edited by jbdev on Tue Aug 21, 2007 3:43 pm, edited 1 time in total.

User avatar
matthewhayashida
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Sat Feb 10, 2007 8:26 pm
Location: Abbotsford, BC
Contact:

Re: How do I getView() or tell If I am at the home page

Post by matthewhayashida » Tue Aug 14, 2007 8:26 pm

Here is a way to tell if you are on the frontpage

Code: Select all

<?php if ( $_REQUEST['option'] == "com_frontpage" ) {
echo '<div id="main">';
Text
echo '</div><div id="right">This code displays if page is the frontpage</div>';
}
else {
echo '<div id="main">';
Text
echo '</div>';
}?>

I hope this helps.
-Matt Hayashida

User avatar
Chris Davenport
Joomla! Intern
Joomla! Intern
Posts: 95
Joined: Thu Aug 18, 2005 8:57 am
Location: Shrewsbury, Shropshire, United Kingdom

Re: How do I getView() or tell If I am at the home page

Post by Chris Davenport » Tue Aug 14, 2007 9:20 pm

Joomla! Core Team Member | Documentation Working Group Coordinator

"Reality is merely an illusion, although a very persistent one" - Albert Einstein
"We are suspended in language such that we don't know what is up and what is down" - Niels Bohr

User avatar
matthewhayashida
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 114
Joined: Sat Feb 10, 2007 8:26 pm
Location: Abbotsford, BC
Contact:

Re: How do I getView() or tell If I am at the home page

Post by matthewhayashida » Tue Aug 14, 2007 9:55 pm

Cool. I was wondering how to do that in 1.5 Ive been converting a new templates. Thanks!
-Matt Hayashida

mike_dowler
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Mon Nov 06, 2006 11:03 pm
Location: Birmingham, UK

Re: How do I getView() or tell If I am at the home page

Post by mike_dowler » Tue Aug 14, 2007 10:17 pm

However, this doesn't really answer the OP's question.  The 'frontpage' view does not need to be used on the home page (it can be used anywhere on the site) and the home page does not need to show the 'frontpage' view (it can show a single article if desired).

So, is there a way to check that a user is on the home page, i.e. the page at the top of the main menu (J!1.5) and the one shown when someone goes to http://www.mysite.com ?

jbdev
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Mar 05, 2007 3:36 pm

Re: How do I getView() or tell If I am at the home page

Post by jbdev » Wed Aug 15, 2007 1:50 pm

Thanks  for the help.

This does not work as well because there is not always a request or "view" is not set. Unless I am missing something

Code: Select all

<?php
if (JRequest::getVar('view') === 'frontpage') {
   echo 'This is the front page';
}
?>





here is what I did for now

I created a custom module position and set a empty module for display on the home page in that position.  I do not have any calls in the template for the module position but I can use the countmodules() funtion to determine if I am on the home page and fire off what ever code I need.

so if $this->countModules('homefakeid') then else ... etc etc etc

Works for now :)
Last edited by jbdev on Wed Aug 15, 2007 1:59 pm, edited 1 time in total.

User avatar
CirTap
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Mon Dec 12, 2005 5:34 pm
Contact:

Re: How do I getView() or tell If I am at the home page

Post by CirTap » Wed Aug 15, 2007 2:57 pm

Hi,

someplace else I recommended to ask the Menu instance.
*IF* your homepage has a link in the mainmenu and *IF* this page is shown == active, you can use this code as well:

Code: Select all

 $jmenu = &JMenu::getInstance();
 $menu  = $jmenu->getActive();
 // return ($menu->query['view'] == 'frontpage');
 return ($menu->home);


Have fun,
CirTap
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
louis.landry
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 101
Joined: Wed Aug 17, 2005 11:03 pm
Location: New Orleans, Louisiana
Contact:

Re: How do I getView() or tell If I am at the home page

Post by louis.landry » Sat Aug 18, 2007 6:36 am

Try something like:

Code: Select all

<?php
$menu = &JMenu::getInstance();
if ($menu->getActive() == $menu->getDefault()) {
  // The default menu item is the active one .... otherwise said, we are on the front page of the site
}


Something like that should get it done.

Louis
Project Manager :: Developer
http://www.webimagery.net
A hacker does for love what others would not do for money.

jbdev
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Mar 05, 2007 3:36 pm

Re: How do I getView() or tell If I am at the home page

Post by jbdev » Tue Aug 21, 2007 3:44 pm

Thank you that worked perfectly :)



louis.landry wrote:Try something like:

Code: Select all

<?php
$menu = &JMenu::getInstance();
if ($menu->getActive() == $menu->getDefault()) {
  // The default menu item is the active one .... otherwise said, we are on the front page of the site
}


Something like that should get it done.

Louis


Post Reply