hey there,

I have written a module (TARDIS) that displays chronological lists of nodes using blocks and pages.

among other things, users can select the view mode to be displayed on the pages. but custom view modes cause the title to disappear.

I was really puzzled, so I created a custom view (using Views, really) in which I displayed nodes using custom view modes. to my surprise, the title disappeared from the view as well.

so, is this a known limitation of drupal_set_title()? what should I do to circumvent this? I thought about rendering a simple HTML like <h1>$title</h1> but it shows up in the content section.

any help is greatly appreciated. thanks in advance!

Comments

Hello,
I believe you are comparing apples and oranges.

The method "drupal_set_title" sets a page attrbute.

Page.title is "apples" and node.title is "oranges". Nodes are not pages and pages are not nodes :) A page is a "html page" (a web page).

Content view modes set which node fields (attributes) are displayed. So I recommend inspecting the view mode (verify that node.title (remember that is different than page.title) is included, verify the node.title has a value).

Good Luck :)

Thinking is the best way to travel.

hi @goofus, thanks for the reply.

yes, I thought drupal_set_title() was meant to set both the H1 in the page (which I know differs from a node object) and the HTML title attribute.

since what my module does is basically build a query and present it as a page, it's important that both the page title and node titles show up on the right places. ;)

in fact, it works for node teasers, RSS and other view modes - but not Full node or custom view modes.

cheers,
Luciano

_________________________

"There is no off position on the genius switch."
- David Letterman

Hello,
Thank you for the reply.

I recommend inspecting the intermediate results. Either the title data is not present, or the display routine (E.G. theme) is not rendering the the title data. For example, you mentioned a query, does the query results contain the title data?

Next, I would set a break point on hook_entity_view and/or hook_node_view to see if there is any unexpected alterations occurring ( I.E. some module invoking something like hook_view_entity_alter().

Finally, I would set a break point in one the template.php functions. See if the title data has made it that far.

Once you locate where the issue is occurring, then you can detail a fix.

Good Luck :)

Thinking is the best way to travel.

Hello,
Thank you for the reply.

I recommend inspecting the intermediate results. Either the title data is not present, or the display routine (E.G. theme) is not rendering the the title data. For example, you mentioned a query, does the query results contain the title data?

Next, I would set a break point on hook_entity_view and/or hook_node_view to see if there is any unexpected alterations occurring ( I.E. some module invoking something like hook_view_entity_alter().

Finally, I would set a break point in one the template.php functions. See if the title data has made it that far.

Once you locate where the issue is occurring, then you can detail a fix.

Good Luck :)

Thinking is the best way to travel.

Gotta show us some code. If your title is disappearing, check the following:

1) Is the title there, but hidden by CSS?
2) Are you calling drupal_set_title() somewhere?
3) Are you settings a variable that looks something like $var['#title'] to FALSE somewhere, in a preprocess or theme function?
4) Is the page title set? (the title in the browser)

Jaypan
Our newest Drupal site: PacificAikido.com (Drupal showcase)

@Jaypan,

answering your questions:
1) Is the title there, but hidden by CSS?
nope. it won't show up at all when nodes are rendered as Full node or a custom view mode. other view modes, like teaser and RSS, work as expected.

2) Are you calling drupal_set_title() somewhere?
yep, please check the code below.

3) Are you settings a variable that looks something like $var['#title'] to FALSE somewhere, in a preprocess or theme function?
no. also, there's no preprocess functions and minimal theming.

4) Is the page title set? (the title in the browser)
yes it is.

here's the function that builds a TARDIS page:
(the relevant stuff is from the first occurence of drupal_set_title() on.)

<?php
function tardis_page($tardis_page_name) {
 
// $tardis_page_name is the argument used to retrieve a TARDIS page from
  // the db. It's immediately stripped from the $args array afterwards.
 
$args = func_get_args();
 
array_shift($args);
 
$tardis_page = db_select('tardis_pages', 'tp')
    ->
fields('tp')
    ->
condition('name', $tardis_page_name)
    ->
execute()
    ->
fetchObject();
 
// Those are the page settings as retrieved from the db:
 
$name = $tardis_page->name;
 
$title_date = $tardis_page->title_date;
 
$nodes_per_page = $tardis_page->nodes_per_page;
 
// Node types are stored in serialized form and must be unserialized.
 
$node_types = unserialize($tardis_page->node_types);
 
// Fetch fields used by submodules in the query.
 
_tardis_submodule_fields($tardis_page, $tardisdate_field, $tardisi18n_lang);
 
// How did the user choose to append the current date to the page title?
 
$tardis_page_title_date = $title_date;
 
// Unless the user asked not to append the date to the page title:
 
if ($tardis_page_title_date != 'no_date') {
   
// Get the current page title.
   
$title = drupal_get_title();
   
// Retrieve URL arguments.
   
$tardis_query_arg = _tardis_query_arg($nodes_per_page, $node_types);
   
// If we have a month, there's a distinction between
    // how months are displayed: numbers or names.
   
if (count($tardis_query_arg) > 1) {
      switch (
$tardis_page_title_date) {
       
// Month names:
       
case 'years_month_names':
         
// Retrieve month names using this helper function.
         
$tardis_month_names = _tardis_month_names();
         
$tardis_month_number = $tardis_query_arg[1];
         
drupal_set_title($title . ": $tardis_month_names[$tardis_month_number], $tardis_query_arg[0]");
          break;
       
// Month numbers:
       
case 'years_month_numbers':
         
drupal_set_title($title . ": $tardis_query_arg[1]/$tardis_query_arg[0]");
          break;
      }
    }
   
// If there's only a year, that distinction is not needed.
   
if (count($tardis_query_arg) == 1 && $tardis_query_arg[0] != '') {
     
drupal_set_title($title . ": $tardis_query_arg[0]");
    }
  }
 
// Calls the page query function.
 
$result = _tardis_query_page($nodes_per_page, $node_types, $tardisdate_field, $tardisi18n_lang);
 
// Assemble a list of NIDs.
 
$nids = array();
  foreach (
$result as $data) {
   
$nids[] = $data->nid;
  }
 
// Load a list of node objects with the NIDs.
 
$nodes = node_load_multiple($nids);
 
// TARDIS Render integration.
 
if (module_exists('tardisrender')) {
   
$tardisrender_view_mode = $tardis_page->tardisrender_view_mode;
  }
  else {
   
$tardisrender_view_mode = 'teaser';
  }
 
$views = node_view_multiple($nodes, $tardisrender_view_mode);
 
// Add those objects to the output and render them.
 
$output = '';
  foreach (
$views as $view) {
   
$output .= render($view);
  }
 
// Page results?
 
$output .= theme('pager');
  return
$output;
}
?>

thanks for the assistance!

cheers,
Luciano

_________________________

"There is no off position on the genius switch."
- David Letterman

sorry, folks. I installed a fresh copy of D7 (with my module) in a local environment, re-did my steps, and the problem vanished. it wasn't there.

I guess it might be related to my webhost, but whatever it is it's not related to Drupal.

anyway, thanks for the assist!

cheers

_________________________

"There is no off position on the genius switch."
- David Letterman