1 <!-- $Id: theme-node-templates.html,v 1.1.2.5 2008/12/08 20:15:00 yched Exp $ -->
2 <h3>Template files
</h3>
4 <p>All themes usually come with a default
<span class=
"code">node.tpl.php
</span>
5 template. Drupal core lets you use the following variant (suggestion):
</p>
8 <dt>node-
<CONTENT_TYPE_NAME
>.tpl.php
</dt>
10 ex:
<span class=
"code">node-story.tpl.php
</span> - If present, will be used
11 to theme a 'story' node.
15 <p><strong>Important:
</strong> whenever you add new template files in your theme, you
16 need to rebuild the theme registry, or the theme engine won't see them.
<br/>
17 You can do that by :
<br/>
18 - visiting the
<a href=
"&base_url&admin/build/modules">Administer modules
</a> page
<br/>
19 - or using
<a href=
"http://www.drupal.org/project/devel">Devel module
</a>'s
20 'clear cache' link.
</p>
22 <h3>Template variables
</h3>
24 <p>CCK makes the following variables available in your theme's node templates:
</p>
27 <dt>$
<FIELD_NAME
>_rendered
</dt>
29 Contains the rendered html for the field, including the label and all the
30 field's values, with the settings defined on the
<strong>Display fields
</strong> tab.
33 <dt>$
<GROUP_NAME
>_rendered
</dt>
35 Contains the rendered html for the fieldgroup (if any), including the label
36 and all the group's fields, with the settings defined on the
<strong>Display
37 fields
</strong> tab.
<br/>
38 This variable therefore includes the html contained in all the
39 <span class=
"code">$
<FIELD_NAME
>_rendered
</span> variables for the
45 Contains the raw values of the fields, in the usual array-format used
46 internally by CCK. What you find in there depends on the field type.
<br/>
47 Each value also contains a
<span class=
"code">'view'
</span> element, that
48 holds the ready-to-display value as rendered by the formatter. For instance:
53 'view' =
> '
<a
href=
"node/5">Title of node
5</a
>',
56 <strong>Raw data are not sanitized for output, it is therefore not
57 advised to use them directly
</strong>. Use the
<span class=
"code">'view'
</span>
58 value, or run the values through
<span class=
"code">content_format()
</span>.
62 <h3>Excluding fields from the $content variable
</h3>
64 <p>By default, the
<span class=
"code">$content
</span> variable used in node
65 templates contains the rendered html for the whole node : CCK fields and
66 fieldgroups, but also body, file attachments, fivestar widgets, ...
</p>
68 <p>If for some fields you want to use the more fine-grained variables described
69 above, you might want to use the
<strong>Exclude
</strong> checkboxes on the
<strong>Display
70 fields
</strong> screen, so that the output of those fields is excluded from the
71 <span class=
"code">$content
</span> variable.
</p>
73 <p>You can then customize the display and layout of some CCK fields or groups
74 using the
<span class=
"code">$
<FIELD_NAME
>_rendered
</span> /
75 <span class=
"code">$
<GROUP_NAME
>_rendered
</span> variables, and trust
76 <span class=
"code">$content
</span> to display 'the rest' without getting
77 duplicate information.
</p>
79 <h5>Advanced trick
</h5>
80 <p>The
<strong>Exclude
</strong> checkboxes affect all active themes. On sites with multiple
81 themes, however, the list of fields to exclude from
<span class=
"code">$content
</span>
82 might need to be different across the themes, depending on how their respective
83 node templates are structured.
</p>
85 <p>A theme can bypass those settings by overriding the
<span class=
"code">theme_content_exclude()
</span>
86 function to specify the list of fields to exclude for this theme (see the
87 PHPDoc of the function for more information).
</p>
90 <h3>Special case : nodes in nodereference fields
</h3>
92 <p>In addition to the above, the following suggestions will be looked for
93 in priority for nodes that are displayed as values of a nodereference field using
94 the 'teaser' or 'full node' formatters:
</p>
97 <dt>node-nodereference-
<REFERRING_FIELD_NAME
>-
<TYPE_NAME
>.tpl.php
</dt>
99 ex:
<span class=
"code">node-nodereference-field_noderef-story.tpl.php
</span> -
100 If present, will be used to theme a 'story' node when refererenced in the
101 'field_noderef' field.
104 <dt>node-nodereference-
<TYPE_NAME
>.tpl.php
</dt>
106 ex:
<span class=
"code">node-nodereference-story.tpl.php
</span> - If present,
107 will be used to theme a 'story' node when refererenced in any nodereference
111 <dt>node-nodereference-
<REFERRING_FIELD_NAME
>.tpl.php
</dt>
113 ex:
<span class=
"code">node-nodereference-field_noderef.tpl.php
</span> - If
114 present, will be used to a node refererenced in the 'field_noderef' field.
117 <dt>node-nodereference.tpl.php
</dt>
119 If present, will be used to theme nodes referenced in nodereference fields.
123 <p>The following additional variables are available in templates for referenced nodes:
</p>
126 <dt>$referring_field
</dt>
127 <dd>The nodereference field that references the current node.
</dd>
129 <dt>$referring_node
</dt>
130 <dd>The node referencing the current node.
</dd>