Hi,

I'm trying to add a subheadline ("subtitle", "untertitel") to my content types; it's supposed to show up below the node's title. I managed to accomplish this, but now the subheadline renders twice, once in the headline section and one more in the body section. Is there a way to suppress displaying only this one field in the node's body?

That's my approach:

(1) Created a textfield via CCK called "subheadline", positioned it directly below the "title" field from Drupal core in the input form;

(2) Added the field to a node template, e.g. node-article.tpl.php:

<?php if ($page == 0): ?>
<h1 class="title"><a href="<?php print $node_url ?>"><?php print $title ?></a></h1>
<h1 class="untertitel"><?php print content_format('field_untertitel', $field_untertitel[0]); ?></h1>
<?php else: ?>
<h1 class="title"><?php print $title ?></h1>
<h1 class="untertitel"><?php print content_format('field_untertitel', $field_untertitel[0]); ?></h1>
<?php endif; ?>

Now the field ist showing up in the right place, directly below the subheadline.

(3) Added formatting to common.css

.node .untertitel {
  background: transparent;
  color: #fff;
  font-size: 1.1em;
  font-weight: bold;
  font-style: italic;
  margin: 0;
  padding: 2px 10px 2px 10px;
}

Now the subheadline looks pretty nice in my theme (Slash).

However, the "subheadline" field shows up in the node's body. Since it's white on white background it's pretty invisible, but it takes up screenspace and messes up the page layout.

What I tried so far:

(1) Calling it with "display:none" from common.css solves the problem, but lets the subheadline disappear in the header, also. Thus this is not an option - or is there any way to theme the same field differently at divverent positions?

(2) http://drupal.org/node/206980 does not cover problems like mine.

(3) http://www.davidnewkerk.com/book/30 suggests to replace

<?php
print $content
?>
in page.tpl.php with

<?php print $node->content['body']['#value'] ?>

This is an interesting approach, but requires to theme *all* cck fields plus taxonomy terms plus images etc. That seems much of a overkill just to get a subheadline.

(4) Content Templates. I'd like to avoid this (running yet another module...).

Am I missing something? Are there other ways to get a properly formatted subheadline into Drupal?

Thanks for any ideas and pointers!

Greetings, -asb

Comments

Sorry, for the above to "work", it's necessary to add an field-field_untertitel.tpl.php, where "untertitel" is the computer-readable name of the CCk subheading field.

It should include somthing like this:

<div class="untertitel">
  <?php foreach ($items as $item) {
    print
$item['view'] ?>
<br/>
  <?php } ?>
</div>

If this field template is not available, the CCK subheading field is rendered readable (not "invisible" in white on white, as described above).

Greetings, -asb

CCK fields will display in the body of a node useless you tell them not to. You can turn off the display for your subheadline field by setting the options on the display fields page to hidden. You'll find the display fields page as a tab on every content type admin section - so, for example, the one for the article content type will be here admin/content/types/article/display

The above is the simple solution - not necessary the correct solution - because Drupal indexes what is returned by the node view hook and therefore your subtitle will not be indexed if you hide it in this way! Here are two solutions partial solutions though hopefully someone else will suggest a better way!

1. You can set the css for the field to display none as suggested in your solution (1) but then override the display:none for your field will something like this:

h1.untertitel .whatclassyourfieldhas {
  display:block;
}

2. Or your can remove the field from your .tpl.php and use the weight setting on the content type fields page (admin/content/types/article/fields) to move your field to the top of the menu. And then style the field appropiately. Maybe the downside of this for your will be that any tab menus a page has (like view and edit if the user has permissions) will appear between the title and subtitle.

Also, looking at your .tpl.php file you probably have the page title appearing twice as usually themes print the page title in the page.tpl.php if the node is being shown as a whole page ($page is true).

Alex Pott

Hi Alex,

> CCK fields will display in the body of a node useless you tell them not to.

That's exactly what I'd like to do: tell exactly one CCK field not do show up in the node's body ;-) I was hoping that there is a code snippet for template.php to do this...

> You can turn off the display for your subheadline field by setting the options on the display fields page to hidden.

This seems like a manageable workaround. However, besides indexing there seem to be some side effects; after disabling the subheading field for teasers and the body on the display fields tab, with caching disabled, the workaround seemed to work; after enabling caching again, the field doesn't show up in teasers at all but still twice in the full node view. Possibly some caching issue (I'm using the "Boost" module) that needs further investigation.

Thanks also for the other hints, I'll need some time to experiment with those ideas. What would be the drupaliest way to follow?

Greetings, -asb