Render Array for hook_field_formatter_view not displaying I'm updating this question on the suggestion of the initial provided answer. 

When trying to render out the content of my custom field, outputting the data into a custom theming function to render on to the page when using the suggested method is resulting in the theming function being ignored, even when attempting to output just static strings of text or using the devel module to test it, nothing happens, the code is updated as below

/**
 * Implements hook_field_formatter_view().
 */
function mymodule_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
  foreach ($items as $delta =&gt; $item) {
    if ($file = file_load($item['image'])) {
      list($hours, $mins, $secs) = explode(':', $item['time']);
      $time = ((3600 * $hours) + (60 * $mins) + $secs);
      $element[$delta] = array(
        '#theme' =&gt; 'mymodule_formatter',
        '#image' =&gt; (array) $file,
        '#time' =&gt; $time,
        '#comment' =&gt; $item['comment'],
      );
    }
  }
return $element;
}


Hook and Theming function

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return array(
    'mymodule_formatter' =&gt; array(
      'variables' =&gt; array('variables' =&gt; array()),
      'file' =&gt; 'theme_mymodule.inc',
    ),
  );
}


In the theme_mymodule.inc file

/**
 * Returns HTML for a MyModule.
 */
function theme_mymodule_formatter($variables) {
  $output = t('test');

  return $output;
}


I think I'm a little confused about the naming of the theme hook, when I was copying the image module, the #theme variable was just declared as 'image_formatter' but the function named was 'theme_image_formatter', I'm wondering if I've declared my theme hook wrong.

--Previous question--

Im trying to write my own custom field in my own module, I've written the field setup, and it's accepting and evaluating data fine, that's all good. I'm struggling to grasp what I need to do when trying to write my own theming output function. As an example to the parts of code I'm working on:

/**
 * Implements hook_field_formatter_view().
 */
function mymodule_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
  foreach ($items as $delta =&gt; $item) {
    if ($file = file_load($item['image'])) {
      list($hours, $mins, $secs) = explode(':', $item['time']);
      $time = ((3600 * $hours) + (60 * $mins) + $secs);
      $variables = array(
        'image' =&gt; (array) $file,
        'time' =&gt; $time,
        'comment' =&gt; $item['comment'],
      );
      $element[$delta] = theme('mymodule_formatter', $variables);
    }
  }
return $element;
}


And my theming function

/**
 * Returns HTML for a MyModule.
 */
function theme_mymodule_formatter($variables) {
  $item = $variables['image'];
  $image = array(
    'path' =&gt; $item['uri'],
  );

  if (isset($item['attributes'])) {
    $image['attributes'] = $item['attributes'];
  }

  if (isset($variables['image_style'])) {
    $image['style_name'] = $variables['image_style'];
    $output = theme('image_style', $image);
  }
  else {
    $output = theme('image', $image);
  }

  return $output;
}


Now this returns the correct HTML for my image, so it actually returns a string like

&lt;img typeof="foaf:Image" src="[img_path]" width="120" height="90" alt="" /&gt;


However this doesn't actually render on my page, it doesn't come back with an error, it just doesn't show anything. 

When I change my $element[$delta] line in my hook_field_formatter_view() function to say

$element[$delta] = array('#markup' =&gt; theme('mymodule_formatter', $variables));


By putting the element into a '#markup' array, it does actually render the image, however I don't want to just throw everything into a '#markup' array if that's not the proper way of doing it.
To add markup that's already been prepared to a render array, you would indeed use #markup. There's nothing wrong with using it where appropriate.

However, since you're preparing the markup in the same function anyway, you may as well use the render array version of the call to theme(), e.g.

$element[$delta] = array(
  '#theme' =&gt; 'mymodule_formatter',
  '#image' =&gt; $image,
  '#another_var' =&gt; 'foo',
);


It provides better structure, makes it easier for other modules to alter if necessary, and is better for caching.