Community

How do I Render content type fields in page.tpl.php?

Hi Everyone,

I am trying to access "field_top_banner_image" from my page content type and print it before $page['content']

I printed the $page array and see where "feild_top_banner_image" is but... when I get down to #object

$page['content']['system_main']['nodes'][1]['body']['#object']

I cannot access anything past #object... Idk if the # has something to do with it or what?

$page['content']['system_main']['nodes'][1]['body']['#object'] //works
$page['content']['system_main']['nodes'][1]['body']['#object']['field_top_banner_image'] //error

Comments

I suspect you are trying to

I suspect you are trying to do this so it shows before the title, you can achieve this in several ways without hard coding in page.tpl.php. Two quick approachs are use Display Suite which extends the "Manage display" tab for content types and make a view that takes the current node id to make a block that displays the image.

Thanks so much!I thought is

Thanks for that solution.

I would rather do it in the page.tpl.php file though.
It seems like I have everything just need to get the syntax right.

You do understand that is not

You do understand that is not a best practice?

I do not.I tend to use

I do not.
I tend to use modules as minimal as possible because it creates messy DOM structure.
I am curious to know why it isn't best practice.

I understand what you are saying. Looks like I need to create a view for the image and then place it before the content using blocks.
I should be able to do that pretty easily.

Thanks

**Your solution worked great! Thanks Again

$banner_array =

$banner_array = $page['content']['system_main']['nodes'][$node->nid]['body']['#object']->field_top_banner_image;

My co-worker helped me figure this one out. This is what you need to do to access objects in an array.

nobody click here