I am writing a custom template and I wanted to display the office hours data. I am using this code
print_r($centre_node->field_openinghours);
print theme('office_hours_formatter_default',$centre_node->field_openinghours);
where $centre_node->field_openinghours contains
Array
(
[0] => Array
(
[day] =>
[starthours] =>
[endhours] =>
)
[1] => Array
(
[day] => 1
[starthours] => 1000
[endhours] => 1600
)
...etc
Although nothing is displayed. Do you know what I am doing wrong ? (I am relatively new to drupal development but this seemed the way to call a module template function from your own template)
Comments
Comment #1
exobuzz commentedLooking at the theme_office_hours_formatter_default code, it looks as though I'm passing it the wrong data. it wants some structure with #field_name, #type_name.
I think I am a bit closer. I need to use node_build_content I think, and then pass the ->content['field_openinghours'] to your theme function, but it doesnt work (yet). I guess it might just be easier for me to process the display manually.
Comment #2
iTiZZiMO commentedtake me a long time, but here is the working code:
if ($node = node_load($nid)) {
$elements['#theme'] = 'office_hours_formatter_default';
$elements['#field_name'] = 'field_office_hours';
$elements['#type_name'] = 'provider_profile';
$elements['#formatter'] = 'default';
//$elements['#node'] = $node;
foreach ($node->field_office_hours as $field)
{
$elements[] = array ('#item' => $field, '#weight' => $field['day']);
}
$elements['#theme_used'] = true;
$elements['#type'] = 'markup';
return theme('office_hours_formatter_default',$elements);
}
Comment #3
johnv