we're trying to build a template for the custom field we developed. We don't want to put the template into our theme folder since the template should work between different themes. As far as we know we have the option of putting a custom field.tpl.php somewhere or override theme_field() in our module. What we've been trying with naming these files/functions kind of didn't work out and now we need your help. :-)

What's best practice with building templates / templating for custom fields, where to put it and how to name it?

Thanks! :)

1 Answer 1


When you define your module's theme info in theme_hook(), you can use drupal_get_path() to find the path to your module, and the path array key in your theme implementation array to point to the directory your tpl is in.

A working example would be:

function field_collection_theme($existing, $type, $theme, $path) {

  $path = drupal_get_path('module', 'field_collection');

  return array(
    'field_collection_op_links' => array(
      'path' => $path . '/includes/theme',
      'template' => 'field-collection-op-links',
      'render element' => 'op_links',

Where the field_collection_op_links.tpl.php is in field_collection/includes/theme/, no matter where field collection is installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.