2

I am creating a module for searching a library of books. I have created a set of tabs on the module display page.

  • Search
  • Results
  • Item

The title when the Search page is selected (or default) is as I would expect "Search" however when I go to either of the other tabs (via link or a click) the title of the page is shown as "Home". While not a major issue it doesnt look good.

I have set the 'title' attribute of the render array for each page to 'Results' and 'Item Details' respectively. How do I force this title rather than 'Home'.

I have noticed the same behaviour for pages using 'MENU_CALLBACK'.

2

I have noticed the same behaviour for pages using 'MENU_CALLBACK'.

I had this problem today, and changing the menu type to MENU_SUGGESTED_ITEM allowed the title callback to be used.

2

The page title is by default the title defined in hook_menu for the menu item. If you want to alter the title, you should use drupal_set_title.

Note: Drupal set title can't be used to late in the theming process (like template_preprocess_page), as the value for the title has already been populated at that point. Using it in the menu callback should work just fine.

  • But It's not. The title shows correctly for the default tab, but shows Home for the other tabs even though I have set title. I will try drupal_set_title though. – Toby Allen Apr 30 '11 at 9:03
  • 1
    This is currently by design. Local tasks always use the title of the tab_root, which is the nearest normal menu item. If you want a different title, you have to use drupal_set_title(). – Berdir Apr 30 '11 at 9:07
1

This relates to an outstanding bug in Drupal core.

Often when you have menu tabs you want the page title to be that of the parent page, not the current tab. The tab in effect is its own sub-title.

This doesn't work all the time though. In the case where the parent page is not relevant (in this case the home page) you end up with an unexpected page title.

This issue is currently in progress to resolve this problem. The current patch in comment #26 specifically singles out the case where the parent page is the <front> page and then uses the title of the current tab.

I am using that patch and it seems to work as expected.
It fixes the very long standing problem of incorrect "Home" titles on those user login/register/password pages.

  • THAT is interesting to be aware of ! – Pierre.Vriens Aug 11 '15 at 6:10
0

Perhaps you did not set one tab to be the default local task. MENU_DEFAULT_LOCAL_TASK is the constant to use in the definition of such menu callbacks.

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.