1

I am printing the node body using PHP on an admin view via a template; however, when I do this, the text comes out as one giant block (spacing is ignored). However, when I go to edit the node, the content is spaced properly.

My code looks like this:

print "Body: " . $body[0]['value'];

What do I need to change to make sure the spacing/formatting is printed out properly?

3 Answers 3

3

I believe you're looking for the check_markup() function:

Runs all the enabled filters on a piece of text.

Note: Because filters can inject JavaScript or execute PHP code, security is vital here. When a user supplies a text format, you should validate it using filter_access() before accepting/using it. This is normally done in the validation stage of the Form API. You should for example never make a preview of content in a disallowed format.

E.g.

$markup = check_markup($body[0]['value'], $body[0]['format']);
1

You can use this drupal default function "field_view_field()".

For this to be done you just need to load that particular node by its node id

<?php
$node = node_load(10);
$display = array('type' => 'full_html');
 $output = field_view_field('node', $node, 'body', $display);
 print render($output);

?>

$display can have option full_html/filtered_html etc. You can apply more options to the display options to print it in desired format. You can refer this link Here

0

depending on the template and the preprocess, but try render($body)

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.