0

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; ?>

</div>

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?

2 Answers 2

1

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.

4
  • 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(). Feb 17, 2013 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, 2013 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, 2013 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. Feb 17, 2013 at 20:19
-1

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

1
  • Drupal uses CSS classes like .password-strength and CSS IDs like #user-admin-roles. (See user.css.) That is not the issue.
    – apaderno
    Oct 10, 2013 at 17:15

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.