1

I'm using a Bootstrap subtheme, with a custom page.tpl.php override. Within the template file, I see there are variables for $title, $breadcrumbs, and $action_links.

If I wanted to access these inside of a preprocess or process function, let's say to modify the title based on whether or not there is content in a given region, how would I do that?

They don't seem to be passed along in $variables like the rest of the page content. $variables['title'] is not present. Would I use API functions such as drupal_set_title()?

3

This is how I manipulate breadcrumbs in page preprocess function. You can actually do this somewhere else, where you think it fits according to your needs.

/**
 * Implements hook_preprocess_page().
 */
function extremes_preprocess_page(&$variables) {
  // You can use preprocess hooks to modify the variables before they are passed
  // to the theme function or template file.

  //define breadcrumbs array
  $breadcrumb = array();
  $breadcrumb[] = l('SS','<front>');//add homepage first
  //if we are on one of my dynamic pages, we do this
  if (arg(0) == 'node' && is_numeric(arg(1)) && !empty($variables['node']) && _is_dynamic_type($variables['node']->type)) { 
    if (!empty($variables['node']->field_term_reference)) {//we are gonna depend on a term ref field
      //get all parent terms
      $parents = array_reverse(taxonomy_get_parents_all($variables['node']->field_term_reference[LANGUAGE_NONE][0]['target_id']));
      //and add them to breadcrumb array
      foreach ($parents as $parent) {
        $breadcrumb[] = l($parent->name, 'taxonomy/term/' . $parent->tid);
      }
    }
    //set the breadcrumb
    drupal_set_breadcrumb($breadcrumb);
  }
  //if we are on a term listing page
  else if (arg(0) == 'taxonomy' && is_numeric(arg(2))) {//you can also check here, which vocabulary you want
    //easier this time
    $parents = array_reverse(taxonomy_get_parents_all(arg(2)));
    foreach ($parents as $parent) {
      $breadcrumb[] = l($parent->name, 'taxonomy/term/' . $parent->tid);
    }
    if (arg(3) && $type = taxonomy_term_machine_name_load(arg(3), 'vocab_name')) {
      $breadcrumb[] = l($type->name, request_path());
    }
    drupal_set_breadcrumb($breadcrumb);
  }

}

This sample uses taxonomy_machine_name.module which uses the same system with pathauto and is very useful for loading taxonomy terms from url if you set up correctly.

For title, you can go with drupal_set_title() and for action links hook_menu_local_tasks_alter().

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.