1

In my theme_preprocess_taxonomy_term function I am loading a node. Then want to move its "body field" to the content array of my template.

    mytheme_preprocess_taxonomy_term(&$variables){
        $import_content_node_id = 32;
        //load node
        $import_content_node = $node = Node::load($import_content_node_id);
        variables['content']['body'] = $import_content_node->getFields()['body'];
}

This does not work because variables['content']['body'] is NOT a render array.

But from where I get the render array? Or how do I create one from an by script loaded node?

4

You can use the method view() of the field.

Example, to get the render array of the body field as configured in the viewmode full:

$renderarray = $node->body->view('full');

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.