I have a custom node template. Part of which I need to display some data from a related node. I use a view to give me the related node id - for example
$view = views_get_view('my_view');
$view->set_arguments(array($node->nid));
$view->execute();
$centre_nid = $view->result[0]->nid;
$centre_node = node_build_content(node_load($centre_nid));
there is a field in $centre_node that contains "opening hours", that contains the data for that cck field as well as
the data for which theme function renders it etc (i am new to drupal so I'm making assumptions on what the data is for)
[#theme] => office_hours_formatter_default
[#field_name] => field_openinghours
[#type_name] => centre
[#formatter] => default
I want to render this field using the office_hours_formatter_default code that comes with the module. I thought I could do something like
print theme('office_hours_formatter_default',$centre_node->content['field_openinghours']['field']);
or maybe i would just need
print theme('office_hours_formatter_default',$centre_node->content['field_openinghours']);
but I wonder i am going about this the wrong way. I need a single field from this node, and rendered as it would be if i was to visit the default output for that node.
Comments
Hi, I managed to render a
Hi,
I managed to render a single field using the assigned formatter, see the code in #394682: CCK fields (filefield,imagefield,emfield) and fieldgroups for Inline API.
It is basically done exploring the node and calling
content_render().However I am not sure I am doing it the best way, maybe
content_view()anddrupal_render()can be used as well. Follow the issue above to see my next experiments.Regards,
Antonio