1

For testing purposes, I'm trying to manually add a message to the $messages array, in either process or preprocess page function. To be clear, I first tried using

template.php -> mytheme_preprocess_page (&$vars) {}

but then I realized there's no $messages array there, so instead I am doing it via process.page.inc.

The code I have tried, which is not working is:

function mytheme_process_page(&$variables) {
    $variables[messages][] = 'new test message';
    kpr($variables);  
}

I have tried some variations on this, but nothing worked.

1 Answer 1

3

$messages isn't an array of messages; it's the rendered output of theme_status_messages(). From the point at which you're looking to add messages (template_process_page()), Drupal has already processed all the messages it's going to render.

If you're looking to print some debugging messages you can do something like this:

function MYTHEME_process_page(&$variables) {
  drupal_set_message('new test message');

  //This will overwrite any previous messages that were to be rendered
  $variables['messages'] = theme_status_messages(array('display' => null));
}

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.