# How should I display fields for a content type?

I have a complex content type with several user-defined fields. In Drupal 6, I used Contemplate to display the fields in an HTML table. I've just upgraded to Drupal 7 and I'm wondering how to best achieve this now. The Contemplate project seems to suggest that Drupal 7's field display features are the way to go. But how do I create and populate an HTML table with a node's fields in Drupal 7? Do I extend/override a theme?

Update: To clarify, let's say I have several nodes with the same content type history. How do I display each of these nodes in the same specific way, including some of the user-defined fields I've attached to that content type. In addition, I use the pathauto module to give each of these nodes a path like history/<year>.

Show fields for a content type, you have to create a new file node.tpl.php inside your theme. And you have to use the function var_dump, like that:
var_dump(array_keys($content)) //so you can see all the fields availables After that, you can print all the fields inside the node.tpl.php in using the function render: print render($content[FIELDNAME])

• I ended up using this answer. While Views seemed promising, in the end, the quickest way for me to replicate my contemplates was to extend an existing theme with files such as node--history.tpl.php. – dave Jan 7 '14 at 4:12

You can use display suite module to theme your node.

Display Suite allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files. A predefined list of layouts (D7 only) is available for even more drag and drop fun!

If you want to theme your node using code, then you should create template for your node. Check this link for reference.

As as option you can check views module, it basically provides ui to query and display your entities(nodes,users etc.) in different formats(table is one of them) out of the box.

• Thanks @arpitr. I've enabled the Views (and Views UI) modules and had an initial look at creating a view. It seems this module is geared towards displaying groups of nodes. How do I use it to override the default display for a content type? For example, if I have content type called test and a node of type test, how do I configure a view to display this node in the way I want, in particular by placing fields where I want them? – dave Jan 4 '14 at 10:13
• views have filters, you just have to add a filter your view to show results filtered by nid – arpitr Jan 4 '14 at 15:14
• is this a filter criteria or a contextual filter? I've tried both and selected Content: nid as the filter, but what do I set the operator and value to for the former or the settings for the latter? – dave Jan 6 '14 at 7:50
• filter criteria is what you need to add , as the name suggest we use context filter when we need to filter results on basis of some context for dynamic behaviour but in your case we know the node id. use operator as is equal to and value as the node id, to get the node id for your node, you can go and edit your node and see the url it will be like node/edit/%nid% so this %nid% is the value you need to put into your view filter. – arpitr Jan 6 '14 at 8:50
• Actually @arpitr I'm not sure I know the node id. Either that or I'm misunderstanding something. I have many nodes of the same content type and I want to apply the view to all of them when I display the nodes individually. So, for example, if nodes 3 and 4 are both of type test and I visit /node/3 or /node/4 I want the view to apply. I've added a filter criteria with the operator set to equal to and the value set to %nid% but it does not have any effect. The default display for these nodes is still used. – dave Jan 6 '14 at 9:25

As arpitr already wrote, the best way would be to use Views and its contextual filters. Add contextual filter: node id (nid) and provide default value nid. Add the fields you want and enable block display.

E. g. you have an article with "address" field. If you enter the address, it will be displayed in that block only on that page (the one that has address entered). You can display data in table format, grid, list, unformatted etc.

You can find out more about contextual filters here:

https://drupal.org/node/1578558