I have a theme, and for the life of me can't figure out why $content is rendering "array". I have switched to two other themes (framework and seven, and my new theme is based off of the framework theme that is working).

Here is an example of the theme code:

    <div <?php if ($left): ?>id="maincolright" <?php elseif ($right): ?>id="maincolleft" <?php else: ?>id="main" <?php endif; ?>class="nobg node-<?php print $node->nid; ?>">

    <?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block"><ul class="tabs primary">'. $tabs .'</ul>'; endif; ?>
    <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
    <?php if ($tabs): print '<span class="clear"></span></div>'; endif; ?>
    <?php if ($show_messages && $messages): print $messages; endif; ?>
    <?php print $help; ?>
    <?php print $content; ?>


So $content is there, and it should be fine, but on any pages I view, for instance, the page render, the edit page, or even my devel page, show only 'array'. See the screenshot:

enter image description here

Has anyone come across this?


print() is a command that doesn't work with arrays. print_r() will print out arrays for debugging but what you want is print render($content). Drupal uses large render arrays to output content, and they cannot be printed directly.

| improve this answer | |
  • Hey Beth, thanks for the answer, I've never had to do that for Drupal 6, only 7. None of the themes I am using use render(). – Aaron Ortega Feb 17 '13 at 8:14
  • I would throw in a print '<pre>' . print_r($content, TRUE) . '</pre>'; or something similar there in any case to see what is actually in the array. That might shed some light onto what is going on. – Jimajamma Feb 17 '13 at 15:17
  • Jimajamma is right. You can also install devel and use dpm() instad of print_r() if you want to browse arrays and objects. – beth Feb 17 '13 at 17:58
  • Was a bit of user error on my part. Thanks to you both for pushing me to read into the array more. without TRUE and dpm() I wouldn't have discovered it. In my header, I did a module_invoke and when I copy and pasted some old code, I used $content = module_invoke(..); which overwrote $content. Thanks y'all. – Aaron Ortega Feb 17 '13 at 20:19

some other people are saying the modules have a bug where you have to use underscore instead of dash in the div definitions; try tabs_wrapper for example

| improve this answer | |
  • Drupal uses CSS classes like .password-strength and CSS IDs like #user-admin-roles. (See user.css.) That is not the issue. – kiamlaluno Oct 10 '13 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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