I am theming a node for a specific content type and split the theme into whether the node is being displayed as a teaser or full. This error only comes up when you view the full node.

Error: Cannot use string offset as an array in XXXXXX/node--event.tpl.php on line 100

The node displays fine as a teaser, which makes this error even more confusing as the problematic line is used during teaser display. The code below is the one for the teaser part of the template.

  <?php if ($teaser): ?>
  <div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

        <h2<?php print $title_attributes; ?>>
      <a href="<?php print $node_url; ?>"><?php print $title; ?> - 

        <span class="eventdate"><?php print(substr($node->field_date[und][0][value], 0, -9));?></span>
  <div class="content clearfix"<?php print $content_attributes; ?>>
      // We hide the comments and links now so that we can render them later.

    <div class="link-wrapper">
      <?php print $links; ?>
  <?php endif; ?>
  • What version of Drupal?
    – sheena_d
    Apr 16, 2012 at 20:24
  • Currently using 7.12
    – A_funs
    Apr 16, 2012 at 20:39

3 Answers 3


If you get that error, it means that $node->body is not an array, but a string. In that case, PHP would take $node->body[und] as a string offset, and you could not use $node->body[und][0][safe_value].

To notice that both und, and safe_value are considered from PHP two constants, but Drupal doesn't define those constants. In that case, PHP would use as value of the constants und, and safe_value, the values of the strings 'und', and 'safe_value', but you should not rely on that.


In Drupal 7, you should be utilizing the render() function rather than directly printing a node field's value. So, line 100 of your node.tpl.php file should read:

print render($content['body']);

If you need to make changes to the data in the $content['body'] variable for teaser views, that sort of processing should be done in an implementation of template_preprocess_node(), not in the node template.

More information about your motivation behind the code on line 100 and your desired result would help me to provide a solution more specific to your situation.

  • I am trying to gain complete control over each value in the $node object and how it's displayed. I looked at the drupal documentation for the preprocess function and it's a little unclear. Within this preprocess function am I simply to turn $node->body[und][0][safe_value] into a variable and that variable will be accessible in the node.tpl.php ?
    – A_funs
    Apr 16, 2012 at 21:55
  • I'm not sure why you are trying to utilize $node->body[und][0][safe_value] at all.
    – sheena_d
    Apr 16, 2012 at 22:03
  • Each field in the node template has a corresponding variable you can use, for the body you can use $body[0]['safe_value'].
    – dxc
    Jan 11, 2013 at 19:06

I don't know if this helps, but I encountered this error because I declared an array as a string earlier in my own code.

https://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.empty-string-index-operator (in PHP 7.0 this is allowed, but PHP 7.1+ will not covert stings to arrays)

I can't see enough of your code to inspect the issue, but it's possible something similar maybe happening.


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.