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

exobuzz’s picture

Looking 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.

iTiZZiMO’s picture

take 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);
}

johnv’s picture

Title: Using the office hours display code » Using the office hours display in custom code / programmatically
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.