How do I render this code in block/node page?

print render($page['content']['system_main']['nodes'][$nid]['rc_core_item_avail_form']); 

I tried putting this into a node in the Omega theme and also in a block directly but nothing at all. Can anyone help?

Replay

You cannot use that code in a node or in a block, since in both the cases the $page variable is not available. It seems that code is taken from an implementation of hook_page_alter() or adapted from code used by an implementation of hook_page_alter(). In fact:

  • hook_page_alter() receives $page as argument
  • The documentation for hook_page_alter() shows that, for a node page, $page['content']['system_main']['nodes'][$nid]['body'] is the content of a node body

If rc_core_item_avail_form is a node field, in a block you could use code similar to the following one.

// Load the currently shown node.
$node = menu_get_object();

// Render the field.
$elements = field_view_field('node', $node, 'rc_core_item_avail_form');
print render($elements);

In the case the field could not be visible to every user, but you want to make that field visible to every user when it is shown in the block, then I would use the following code.

// Load the currently shown node.
$node = menu_get_object();

// Render the field.
$elements = field_view_field('node', $node, 'rc_core_item_avail_form');
$elements['#access'] = TRUE;
print render($elements);

Category: nodes Time: 2013-07-29 Views: 1
Tags: nodes

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.126 (s). 12 q(s)