Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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
1  
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 at 18:21
    
And for theming, I would generally recommend to work with Display suite instead of custom templates. –  donquixote Mar 31 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 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 at 18:41
1  
This is done via hook_module_implements_alter(). But you need to know exactly what you are doing! –  donquixote Mar 31 at 19:28

1 Answer 1

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 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 at 18:16

Your Answer

 
discard

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.