I have a specific node-type: resource. The default display of a resource node is not quite what I want, so I need to over ride the themeable output - so far so good. The problem is, I've created my resource node-type through the Drupal 7 GUI. How do I write a module that just over rides the HTML output for this one content-type?

...and, in piggyback to that question - I will have many other node-types that I've created through the GUI, but need custom output for. Is there a way to create just a single module that will handle the custom output for all of these types?


4 Answers 4


I would use a template override on node.tpl.php for the resource type. Just copy it to node--resource.tpl.php and make your changes. Here is a good tutorial.


IMO, a very good approach would be using Display Suite to generate the basic markup/layout and then add the appropriate styling to the theme.


You can use hook_view() and hook_node_view() in your module to customize your node display, or hook_field_prepare_view() to alter individual fields.

On your module within hook_view() and hook_node_view(), you should use a control statement like switch to place the code for each type:

switch ($node->type) {
  case 'resource':
  case 'other':

To see what is inside $node, you can use the Drupal 7 debug() function, like this:

  • Would you consider it an inappropriate design pattern to create a single module that handles the node display of all of the content types? I should add that there are a large number of content types, each of which has a very particular display format.
    – rybosome
    Commented Nov 1, 2011 at 1:23
  • No, I wouldn't consider it inappropriate unless there are so many other features for each one that it makes sense to bundle them into different modules. If you have maybe a lot of custom code for each type but just need it all for node display, you can still make the code more tidy by separating it into functions and reuse some of them. You can also use include files to group functions for the same content type. Adding so many more modules will somewhat affect performance too, so keep it as simple as possible.
    – 5t4rdu5t
    Commented Nov 1, 2011 at 1:51
  • Just a note, that hook_view() will not work for node types setup via the UI, it only works for node types specified with hook_node_info() and it's more or less, not even a hook, but a named callback based on the "base" key from hook_node_info().
    – Mikey P
    Commented Apr 8, 2012 at 20:07

To answer the question about managing the display of all the content types, you may also want to look into adding custom view modes. Display Suite itself may give you what you need, but keep view modes in mind if you need to display several of the node types in a certain fashion or want to display different fields on different tabs in conjunction with Panels or Display Suite.

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.