3

I'm trying to create a custom front page for anonymous users, something like page--front-anonymous.tpl.php.

I could use the page--front.tpl.php template file, and check the role there, but I believe it is possible to create a separate template file for the front page when it is visited from anonymous users.

Any advise?

2 Answers 2

3

in your THEME_preprocess_page(&$vars) hook you can put something along the lines of...

if ($vars['is_front'] && !$vars['logged_in']) {
   $vars['template_files'][]='page-front-anonymous'; // drupal 6
   $vars['theme_hook_suggestions'][]='page_front_anonymous'; // drupal 7
}

which should work using the is_front and logged_in variables set by the various modules before you get to it. if you are using a module, and don't want to rely on weight/execution order, you could do it with:

global $user;
if (drupal_is_front_page() && !$user->uid ) {
.....
0
1

I'm not sure how complicated your page is, but if all of you content is in blocks, you can adjust block visibility using the block access module on a per-role basis. I did that on a project - I ended up with one template file, but different pages based on whether or not someone was logged in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.