My pro开发者_JAVA百科blem 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
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.
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)
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();
}
精彩评论