0

I need to dynamically change the Drupal site title to match the role the current use has, or as an alternative option I need to be able to change it based on the content type that is being viewed (on my installation, each role has it's own content). How can i do that? I'm using Drupal 6

  • Just to clarify: do you mean the page title that appears at the top of the browser window? Could you show an example how it would need to be changed? – Madis Mar 12 '12 at 21:39
  • @Dooshta I am talking about the value you set in Drupal at Admin > Site configuration > Site information > Name. This value is static and is the same on the whole site, instead i need it to be dynamic, and change based on user role and/or content type – Terix Mar 13 '12 at 9:37
1

As much as I know the site name is being output with $site_name in a basic Drupal 6 page.tpl.php file and is also part of the $head_title variable. To change them dynamically you could use template_preprocess_page() in your template.php file. Assuming you want to change one or both of those variables based on the user role you could use the following example:

function mytheme_preprocess_page(&$variables) {
  global $user;
  if (in_array('administrator', $user->roles)) {
    $head_title = explode(' | ', $variables['head_title']);
    $head_title[1] = 'Title for admin';
    $variables['head_title'] = implode(' | ', $head_title);
    $variables['site_name'] = 'Site name for admin';
  }
}

Both the head title and site name variables are modified for the 'administrator' role in this case. It should be relatively simple to make this work for all roles the way you want if writing some custom code is not an issue.

0

The Page Title Module along with Token Module might help you achieve that.

  • Could you describe how? I don't recall conditional tokens. – Mołot Jul 30 '13 at 7:54
0

I wanted to do something similar but append text to the Site Name

function mytheme_preprocess_page(&$variables) {
  global $user;
  $sitename = variable_get('site_name', '');

  if (in_array('administrator', $user->roles)) {
    $variables['site_name'] = t('!sitename for Admins', array('!sitename' => $sitename));
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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