What would be the best way to implement a different frontpage for anonymous user? So that authenticated and anonymous users could have different default frontpages.

Some redirection to different page if user is not logged in? If so, which would be appropriate place for the redirection to take place and can I tell drupal to do that by manipulating some variables or what..?

Tnks

Comments

yuriy.babenko’s picture

Put this into your template.php (theme's folder):

function phptemplate_preprocess_page(&$vars)
{
    if(drupal_is_front_page())
    {
    	global $user;
    	if($user->uid)
    	{
			$vars['template_files'] = array('page', 'page-front');
    	}
		else
		{
			$vars['template_files'] = array('page', 'page-front-anonymous');
    	}	
    }
}

Now clear cache from the 'performance' page (site configuration).

Now create the following files in your theme's folder: page-front.tpl.php and page-front-anonymous.tpl.php.

Copy data from page.tpl.php to these new files and modify at will!

More good stuff at: http://yubastudios.com/blog/drupal-extending-templating
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

grobemo’s picture

You might also try the Front Page module.

CleanCutRogue’s picture

Here's a trick I used before I started creating my own modules.

I created a new Page and gave it a url of 'home'. In your site-info settings, make 'home' your default front page.
Then I made two other Pages and gave one the url of 'welcomeback' and the other the url of 'welcomenew'

Then you edit the 'home' page and place the following php in it:

<?php
  global $user;
  if (intval($user->uid>0)) 
    drupal_goto ('welcomeback');
  else
    drupal_goto ('welcomenew');
?>

Now you have two different front pages: one for registered users (called 'welcomeback') and one for anonymous users (called 'welcomenew'). Edit them as desired.

This works well, though it does result in a double-page load on the server whenever someone visits the front page of the site. It never caused a problem on the sites I've placed this strategy on.

wpanssi’s picture

Thanks to all of you!

--
http://www.sitemedia.fi

aaftaab’s picture

I appreciate your really straightforward and clean approach .

gisle’s picture

The above is very dated. Here is the relevant user contributed documentation: https://www.drupal.org/node/223440

(At the time of writing, it only covers D6 and D7, tho'.)

- gisle