logii
logii

Reputation: 320

drupal_set_message() not working in node.tpl.php template on Drupal 7

My problem is with <?php drupal_set_message('Hello World'); ?>

in node.tpl.php

In node.tpl.php, I have also done <?php print_r(get_defined_vars()); ?> to find out if the theme template is set correctly. The answer is yes.

I also have page_top and page_bottom set in my [theme].info file regions[content] = Content regions[help] = Help regions[page_top] = Page Top regions[page_bottom] = Page Bottom

$messages is outputted in page.tpl.php <div id="messages"> <?php print $messages; ?> </div>

After checking through all these, drupal_set_message() is still not working in node.tpl.php

Upvotes: 2

Views: 1907

Answers (3)

donutdan4114
donutdan4114

Reputation: 1272

Not 100% sure, but you might be able to create a preprocess_node function and pass $messages to the node templates.

function template_preprocess_node(&$vars){
  $vars['messages'] = drupal_get_messages();
}

Upvotes: 0

corbacho
corbacho

Reputation: 9052

Drupal 7 might render the messages before the node templates, that's why you can't see those messages.

Yes, it feels wrong to me too, and here is a little discussion and confirmation about the topic. (Closed: work as designed)

Upvotes: 0

Matt V.
Matt V.

Reputation: 9809

The $messages variable isn't listed in the node.tpl.php documentation for Drupal 7. Do you have the $page_top variable being output in your html.tpl.php? I think that may be where the messages get output in D7.

Upvotes: 1

Related Questions