1

I have a block I am trying to insert into the body field, catch is I want it to appear after the first two paragraphs. I tried using something similar to this in my node.tpl.php:

<?php
$array = explode ("</p>", $content['body']);
$array[2] = $myBlock . $array[2];
$content['body'] = implode("</p>", $array);
?>

//Important: This code snippet needs to be inserted before

<?php
print $content['body'];
?>

This code does insert my block in the body field, but also overwrites all the content in the field.

I'm using Drupal 7.10, any help is appreciated.

1

I think you want to be doing this on $body[0]['value']; And then in your output put echo render($content['body']); see the answer to this post on rendering fields.

  • Thank you! Your tip helped me figure it out. Here is how I got it working: $array = explode("</p>", $body[0]['value']); $array[2] = $myBlock . $array[2]; $content['body'] = implode("</p>", $array); – btotheg Feb 1 '12 at 15:19

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.