1

Printing the drupal messages in page.tpl.php is easy:

<?php print render($messages); ?>

How can I go about doing a similar thing in my Panel layouts?

Notes:

  1. I realise there is 'status messages' pane you can use - I wish to avoid this since admin staff will forget to include it on new pages
  2. I definitely wish to do it in the Panel template because there is a section above where the messages should display that is set by the admin staff
  3. I have tried simply putting that code into mylayout.tpl.php, it didn't work

Here's an example of what I am trying to do:

Layout example

Is there something I can do in a pre-process function to get this to work?

EDIT:

Thanks to @Beebee I rediscovered the template_preprocess_LAYOUT function in my layout's .inc file and added

$variables['messages'] = drupal_get_messages();

now both $variables['messages'] and $messages exist when the template is called but they contain an array of messages rather than the usual rendered output in a string.

4
  • Are you trying to put print render($messages); in mylayout.tpl.php without doing any preprocessing? $messages will be available in page templates because it gets set in template_preprocess_page. I think you'll have to preprocess your panels layout and set $variables['messages'] = drupal_get_messages();, and then you should have the $messages variable available on your layout template.
    – Beebee
    Commented Jan 22, 2015 at 16:32
  • Wow... as usual it's something really simple. That sounds right to me and I've only got 4 hours to award this thing, so please make an answer to that effect and I'll go try it out.
    – Darvanen
    Commented Jan 22, 2015 at 22:05
  • Ah! Found the second half of the answer here.
    – Darvanen
    Commented Jan 22, 2015 at 23:15
  • That is a really elegant solution @Darvanen
    – Beebee
    Commented Jan 23, 2015 at 10:19

4 Answers 4

1

What do you think about using Panels Everywhere? You could then add a message pane to your Default site template and avoid 1.

Also you can disable Block from now on, because all parts of your site, are now panels.

1
  • It's a good suggestions but I think I would still end up with the same problem, in that my default site template is necessarily just the header and footer, and the various different layouts the company wants would go within that.
    – Darvanen
    Commented Jan 14, 2015 at 2:16
1

For anyone else who comes across this requirement, messages weren't printing in the Panel template because they were already being called by the page preprocess function in core.

As per this answer about a similar requirement with nodes, the thing to do is to edit your page preprocess function to include this:

function YOURTHEME_preprocess_page(&$variables) {
  // This disables message-printing on ALL page displays
  $variables['show_messages'] = FALSE;
}

And put this in your preprocess function in your layout.inc file:

function YOURTHEME_preprocess_PANEL_LAYOUT(&$variables) {
  $variables['messages'] = theme('status_messages');
}
1
+50

I have used Panels sparingly but I've made custom regions in themes and used #prefix and #suffix wrappers in the Form API to rearrange HTML on my sites.

Offhand I think you should look for a API hook similar to hook_preprocess_page or hook_process_page, but for Panels to override when viewing content to insert or re-arrange the render array used for the $content. Since Panels isn't exactly straight Drupal API, I'm kinda venturing out into unknown territory but here's the best research I can provide now.

After abit of googling I recommend looking at:

The jist of what I'm trying to help you with is to permanently rearrange the output of a Node page such that you can control where $messages is placed.

At the theme layer you might want to try to set Help (Messages) to a Region within the Panel template -- but if that's not possible, hence my attempt at the above magic.

2
  • Thanks tenken. The last item in your post "set Help (Messages) to a Region within the Panel template" is what I'm after here.
    – Darvanen
    Commented Jan 16, 2015 at 4:21
  • ...and can't seem to get working.
    – Darvanen
    Commented Jan 20, 2015 at 3:56
0

the best integration I could use was having it placed in my html.tpl.php file.

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.