Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to define my own entity.tpl for my custom entity? I am using entity API to declare my entity and its controller and class. I don't want to use entity.tpl of entityAPI but my own tpl.

share|improve this question
I see you are trying to define a custom entity type. I tried it myself, it was a pain until everything worked the way I intended. So good luck! For some inspiration you can have a look at drupal.org/field_collection, github.com/donquixote/drupal-nestedbox, drupal.org/project/typical_entity_example. Also drupal.org/project/entity_operations is something to consider. Either way, you are going to face some research time. – donquixote Mar 31 '14 at 18:21
And for theming, I would generally recommend to work with Display suite instead of custom templates. – donquixote Mar 31 '14 at 18:21
@donquixote I am actually having problem to define my own entity.tpl instead of the one used by EntityAPI .. I don't know where to define it – yeahman Mar 31 '14 at 18:23
my entity's display is something very very specific and very different from default entity.tpl. So, I would have preferred defining my own tpl – yeahman Mar 31 '14 at 18:41
This is done via hook_module_implements_alter(). But you need to know exactly what you are doing! – donquixote Mar 31 '14 at 19:28
up vote 2 down vote accepted

Unfortunately, is not as simple as creating a custom template named ENTITYNAME.tpl.php.

You may want to reconsider theming an entity. Entity-level code should only deal with low-level data manipulation. Rendering for the browser should handled separately by the Drupal theme layer, not the entity itself.

However, if you want to override the theme layer for your entity, you can do it by overriding the page template for your entity (i.e. page–-ENTITYNAME.tpl.php (where "ENTITYNAME" is the machine name of your entity).

But this is probably not what you're asking about. If you insist on theming your entity, there is a solution is written up here: Theming Custom Entities @ Drupal.org.

To summarize: You do it by means of three functions that you place in the module defining the entity:

  • MODULENAME_menu() hook.
  • Page Callback
  • MODULENAME_theme() hook.

The MODULENAME_theme() hook is used create this module's Theme Registry entries.

share|improve this answer
thx for the reply but will the above method be applied globally? What i mean globally is e.g. i display my entity teasers in a view, will it take my tpl? It does not seem so looking at the code. – yeahman Mar 30 '14 at 10:31
@Gisle Hannemyr I don't think you need any hook_menu() for the theming part. drupalcode.org/project/field_collection.git/blob/refs/heads/… – donquixote Mar 31 '14 at 18:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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