0

Below is the structure of a multidomensional array. How can I get the value of "title" or any of the values within #object?

$content (Array, 2 elements)
    links (Array, 5 elements)
    body (Array, 16 elements)
        #theme (String, 5 characters )
        #weight (Integer)
        #title (String, 4 characters )
        #access (Boolean)
        #label_display (String, 6 characters )
        #view_mode (String, 6 characters )
        #language (String, 2 characters ) 
        #field_name (String, 4 characters )
        #field_type (String, 17 characters )
        #field_translatable (String, 1 characters )
        #entity_type (String, 4 characters )
        #bundle (String, 7 characters )
        #object (Object) stdClass
            vid (String, 2 characters )
            uid (String, 1 characters )
            title (String, 55 characters ) **THIS IS THE VALUE THAT I NEED**
            log (String, 0 characters )
            status (String, 1 characters )

The error that I get after implementing AJ's solution is:

Notice: Undefined index: body in include() (line 84 of C:\wamp\www\sdnn_drupal\sites\all\themes\sdnn\node.tpl.php).
Notice: Trying to get property of non-object in include() (line 84 of C:\wamp\www\sdnn_drupal\sites\all\themes\sdnn\node.tpl.php).

line 84 of node.tpl.php is what AJ suggested:

<?php echo $content['body']['#object']->title ?>

1 Answer 1

4

$title=$content['body']['#object']->title;

But it also looks like it might be accessible at:

$title=$content['body']['#title'];

Sign up to request clarification or add additional context in comments.

2 Comments

yep. that's it AJ. I do get the value but I also get the following messages: Notice: Undefined index: body in include(); Notice: Trying to get property of non-object in include(). Any idea what it means?
The best way to determine the actual names of the array indices is to do this: print_r($content); and inspect its output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.