I need to recreate a lot of pages after removing Panels from a site.

In order to print regions in node tpls, I added this to theme_preprocess_node. That's fine but it doesn't work for custom pages.

// Get a list of all the regions for this theme
  foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {

    // Get the content for each region and add it to the $region variable
    if ($blocks = block_get_blocks_by_region($region_key)) {
      $variables['region'][$region_key] = $blocks;
    else {
      $variables['region'][$region_key] = array();

I tried adding that to theme_preprocess_page but it doesn't do anything.

Here is my module. The divs print fine but the regions don't get printed.

function custom_pages_menu() {

    $items['classes-admin/%'] = array(
        'title' => t('Classes'),
        'page callback' => 'page_sidebars',
        'access arguments' => array('edit field_diary_date'),
    return $items;

function page_sidebars() {
    $page_return = "";
    $page_return .= '<div class="container-fluid">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="panel-pane">';
    $page_return .=                     render($region['sidebar_left']); // or $page
    $page_return .=             '</div>
                                    <div class="col-md-6">
                                        <div class="panel-pane">';
    $page_return .=                     render($region['sidebar_right']); // or $page
    $page_return .=                 '</div>

    return $page_return;

This seems like a pretty common thing to do but google isn't giving me anything to work with. I don't want to add them to page.tpl because it's a very complex site and I only want it this way, if possible. Any help appreciated.

  • No idea what your code is trying to do here sorry. As far as I can see $region is undeclared/null in page_sidebars(). I can't see how this code can possibly work.
    – Beebee
    Nov 9, 2017 at 10:15
  • I know. My question is about what to add to template.php or something so it will work. Nov 9, 2017 at 10:26
  • Ha, well I can see it isn't -1 anymore, and I like to think you wouldn't downvote your rules+views partner :) As for my edit, I thought the question reached the standards of SO, and my incorrect assumption that the solution would be lie within template.php would be a common one and searchable. I'm always impressed by your commitment here @Pierre.Vriens. I go through phases where I have time and I don't. Nov 9, 2017 at 19:09
  • Merci for the feedback. My 2 (additional) cents: downvoting questions is cheap: the downvoter doesn't have to "pay" any rep decrease for doing so (like the -1 for downvoting an answer). Therefor, if an anonymous downvote of any of my questions comes in, I just ignore such downvotes, and move on (if the downvoter doesn't want to teach me what's wrong, then why bother, right?). Which is also why I think you should rollback your question to the prior revision, your choice of course. PS: sure this question doesn't need a drupal release indication? I.e. would you want to know answers for D7 or D8? Nov 9, 2017 at 19:18
  • I didn't realise it was free to downvote a question, and I edited my post so I don't look so pissy. Not sure about D7 / D8.. I haven't played much with D8 yet and in general, things I assume would stay the same, generally don't. So I added the 7 tag. I'm off to bed. Have a nice day! Nov 9, 2017 at 19:59

1 Answer 1


Well, replace this line




and replace this line




hope it will work for your case :)

  • My main page.tpl.php is like 500 lines long.. And I'll need to create about 20 new tpls if I do it this way. That's a lot of effort and room for error every time I change the main tpl file. I'd be really surprised if I can't print regions in hook_menu(). I'd print blocks but I want caching per block and only works with regions. Nov 9, 2017 at 10:56
  • Well, then try this, replace this line render($region['sidebar_left']); with render(block_get_blocks_by_region('sidebar_left')); hope it will work for your case and similarly replace this line render($region['sidebar_right']); with render(block_get_blocks_by_region('sidebar_right'));
    – Ain
    Nov 9, 2017 at 11:50
  • Awesome. That works perfectly. Can you edit your question to add that and I'll give it the tick and upvote? Nov 9, 2017 at 11:56
  • 1
    @NiallMurphy I updated my answer :)
    – Ain
    Nov 9, 2017 at 12:06

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.