2

I use Zen and have copy/pasted the STARTERKIT to my foo template. Devel is enabled with the "Rebuild the theme registry on every page load" setting on.

In my completely empty template.php I type in the following and save:

function foo_process_node(&$variables, $hook) {
    dpm('test');
}

I then do drush cc all and refresh page. The message is not shown. If I refresh again the message shows.

If I change test to foobar on the 1st refresh I get the old test and on the second I get foobar.

Why does this happen and how can I avoid it?

Note that this lagging behavior is the same for preprocess and process but not there if I print the message from the foo_page_alter(&$page) function.

1
  • Hm. Maybe it's not a Devel issue but a more generic one because I'm getting the exact same behavior for error messages. I'm seeing the error message of the previous page load.
    – cherouvim
    Commented Apr 10, 2012 at 9:35

3 Answers 3

6

This is a common issue people encounter when themeing Drupal (it used to drive me crazy).

In basic terms what's happening is that the messages held in the $_SESSION super global have already been committed to the page by the time the template file containing your call to dpm() is invoked.

This means that the messages are added to the $_SESSION but aren't dumped out to the messages area until the next page...as $messages has already been set up for/printed in page.tpl.php.

The normal way to get around this is to invoke the dpm() at an earlier stage of the process, like in hook_page_alter() as you mention, or hook_node_view(), etc.

Also I think if you implement your preprocess hook at the module level, rather than the theme level, that your calls to dpm() will happen in time for the messages to be displayed in that particular page request.

0
3

This has been an issue for me as well. Another workaround for this by using kpr($your_variable), which is also a function in devel and that seems to display the output on the first page load.

1
  • works for me... Commented Mar 12, 2014 at 8:17
0

dsm method is called to dpm method. so we need to call dpm.

in dpm -- p indicate the print_r().

dpm is just show the array and object as print_r only difference is it show it in error display block. because internally it use drupal_set_message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.