Question

I would like to assign some content from a node, lets say the body field, into a region. so I cannot theme this content in my node.tpl.php

In the template_process_page(&$vars) i can easily set $page['my_region'] = HTML.

with $vars['node']->body i can access to my body field dada. from there I would like to use the regular theme function to render the body field. to use theme('field',$variables) or render($variables) I need to bring the body-array from:

Array
(
    [und] => Array
        (
            [0] => Array
                (
                    [value] => TEXT
                    [summary] => 
                    [format] => full_html
                    [safe_value] =>  TEXT
                    [safe_summary] => 
                )

        )

)

to sth like:

Array
(
    [#theme] => field
    [#weight] => 1
    [#title] => Body
    [#access] => 1
    [#label_display] => hidden
    [#view_mode] => full
    [#language] => und
    [#field_name] => body
    [#field_type] => text_with_summary
    [#field_translatable] => 0
    [#entity_type] => node
    [#bundle] => article
    [#object] => stdClass Object
        (...)
    [#items] => Array
        (
            [0] => Array
                (
                    [value] => TEXT
                    [summary] => 
                    [format] => full_html
                    [safe_value] => TEXT
                    [safe_summary] => 
                )
        )
    [#formatter] => text_default
    [0] => Array
        (
            [#markup] => TEXT
        )
)

But I don't know how exactly. how can a generate my field with the second array-achitecture. if possible without more db-queries.

thank you for help!

Was it helpful?

Solution

You are looking for field_attach_view

What you would need to do, with your loaded node is something like this:

$fields = field_attach_view('node', $node, 'full');
$body = $fields['field_body'];
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top