Page 1 of 1

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

Posted: Tue Aug 14, 2007 6:15 pm
by jbdev
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 

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

Posted: Tue Aug 14, 2007 8:26 pm
by matthewhayashida
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.

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

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

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

Posted: Tue Aug 14, 2007 9:55 pm
by matthewhayashida
Cool. I was wondering how to do that in 1.5 Ive been converting a new templates. Thanks!

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

Posted: Tue Aug 14, 2007 10:17 pm
by mike_dowler
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 ?

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

Posted: Wed Aug 15, 2007 1:50 pm
by jbdev
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 :)

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

Posted: Wed Aug 15, 2007 2:57 pm
by CirTap
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

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

Posted: Sat Aug 18, 2007 6:36 am
by louis.landry
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

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

Posted: Tue Aug 21, 2007 3:44 pm
by jbdev
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