This commit was manufactured as part of Drupal's Great Git Migration to

create tag 'DRUPAL-5--1-11'.

Sprout from DRUPAL-5 2010-06-09 01:06:29 UTC Karen Stevenson <> '#195688 by jcnventura, add print option to nodeapi.'
parent ff5a570e
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// $Id$
Theming Constructed Content Types
After you have designed your content, you will likely want to lay out the
presentation of the content. This is most easily done with PHPtemplate-based
themes. There are two basic options for theming your content, depending on the
level of control you need to exert.
Theming individual fields
This method is straightforward and allows for sensible defaults, but requires a
modest amount of setup. Place the "field.tpl.php" and "template.php" files in
your theme's folder. If you already have a "template.php" file, you will need
to append the code in this one to your own.
All fields are now rendered using your "field.tpl.php" template. If you want to
change them all the same way (for example, to hide every field label), you can
make alterations to this file. If you want to change the presentation of one
field independently, you should instead make a copy of this file first, and
give it the name "field-field_foo.tpl.php" where "field_foo" is the field name
as listed on the administration page. Changes you make to this file will be
reflected only in that field.
An $items variable is made available to you in your field template. This
contains the content of the field you are rendering. It is always an array, so
that the syntax is consistent whether or not the field allows for multiple
values. Each item has a "view" property that contains the filtered, formatted
contents of the item. You should always use this property in your display for
security reasons, unless you are very familiar with how to properly process
output and avoid scripting exploits.
The included example here ("field-field_my_field.tpl.php") illustrates a
minimalistic approach to field theming, for a single-valued field. For a more
flexible template, start from the included "field.tpl.php".
Available variables in field templates :
$items : an array containg the values of the field.
$items[n]['view'] contains the ready-to-use, filtered, formatted value
$label : the label of the field
$label_display : the display settings for the label ('hidden', 'above', or 'inline')
$field_empty : TRUE if there is nothing to display in the field
$field_type : the type of the field,
$field_name : the name of the field,
$field_type_css : same as above, with '-' signs replaced with '_' for use in css properties
$field_name_css : same as above, with '-' signs replaced with '_' for use in css properties
$field : an array containing the full CCK field object
Theming the node as a whole
If you need more flexibility than is afforded by theming individual fields, you
may theme the entire node as a unit. This allows you to affect field order, to
change the HTML structure to something more complicated, like a table, or even
to exclude fields from the presentation entirely. The setup for theming a node
is simpler than for theming a field; simply create a file called
"node-content_foo.tpl.php" where "content_foo" is the content type name as
listed on the administration page. For an example of the typical contents of
this file, investigate the included example here
("node-content_example.tpl.php") or the "node.tpl.php" file that comes with
your theme.
<div class="my_field">
<?php foreach ($items as $item) {
print $item['view'] ?><br/>
<?php } ?>
<?php if (!$field_empty) : ?>
<div class="field field-type-<?php print $field_type_css ?> field-<?php print $field_name_css ?>">
<?php if ($label_display == 'above') : ?>
<div class="field-label"><?php print $label ?>:&nbsp;</div>
<?php endif;?>
<div class="field-items">
<?php $count = 1;
foreach ($items as $delta => $item) :
if (!empty($item['view']) || $item['view'] === "0") : ?>
<div class="field-item <?php print ($count % 2 ? 'odd' : 'even'); ?>">
<?php if ($label_display == 'inline') { ?>
<div class="field-label-inline<?php print($delta ? '' : '-first'); ?>">
<?php print $label ?>:&nbsp;</div>
<?php } ?>
<?php print $item['view']; ?>
<?php $count++;
<?php endif; ?>
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
<?php print $picture ?>
<?php if ($page == 0): ?>
<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php endif; ?>
<?php if ($submitted): ?>
<span class="submitted"><?php print t('!date — !username', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?></span>
<?php endif; ?>
<div class="content">
Here's one field:
<?php print $field_my_field[0]['view']; ?>
And another:
foreach ($field_my_other_field as $item) {
print '<li>'. $item['view'] .'</li>';
<div class="clear-block clear">
<div class="meta">
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>
\ No newline at end of file
// $Id$
function phptemplate_field(&$node, &$field, &$items, $teaser, $page) {
$field_empty = TRUE;
foreach ($items as $delta => $item) {
if (!empty($item['view']) || $item['view'] === "0") {
$field_empty = FALSE;
$variables = array(
'node' => $node,
'field' => $field,
'field_type' => $field['type'],
'field_name' => $field['field_name'],
'field_type_css' => strtr($field['type'], '_', '-'),
'field_name_css' => strtr($field['field_name'], '_', '-'),
'label' => check_plain(t($field['widget']['label'])),
'label_display' => isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above',
'field_empty' => $field_empty,
'items' => $items,
'teaser' => $teaser,
'page' => $page,
return _phptemplate_callback('field', $variables, array('field-'. $field['field_name']));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment