1

I'm quite new to Drupal (using 7), but I've managed to set up my content types (e.g. 'concert') and I've created a node-concert.tpl.php whose HTML structure I need to rewrite to fit the information particular to the concert content type.

I have a wealth of CCK fields (almost all single-line text fields) in this content type, and I know how to access the contents of a field by using <?php print render($content['field_fieldname']); ?>. My problem is this: Drupal outputs every field on a new line. So, if I have the following fields with the following values:

field_concert_date = January 1, 2013
field_concert_time = 3 PM
field_concert_location = Boston, MA

Drupal will simply output each field value on a new line (all field labels are hidden). The output I want would go something like:

January 1, 2013 at 3PM in Boston, MA

I tried to achieve this by wrapping the output of all three fields in an <h2> tag, like so:

<h2><?php print render($content['field_concert_date']); ?> at <?php print render($content['field_concert_time']); ?> in <?php print render($content['field_concert_location']); ?></h2>

But Drupal still outputs everything (even the hard-coded text inside the <h2> tag) on its own line:

January 1, 2013
at
3 PM
in
Boston, MA

I've looked at Customize a field output and Drupal: Print field without markup as well as done some basic Googling, but I can't quite find a reference to this specific problem. I'm assuming the culprit lies in some extra markup that is getting added somewhere that forces a new line at the end of every field, but I'm not entirely sure where it would be coming from. Is it in field.tpl.php? Or somewhere else? Or is it related to the call to render() (something that forces a line break after render() successfully returns the contents of a field)? Like I said, I'm fairly new to Drupal and haven't yet figured out how to pinpoint small-scale (but important!) problems like this.

Thanks!

An additional note: I'm in the process of creating a Drupal theme from scratch, and so far the only CSS I'm pulling in is a CSS Reset.

4

1 回答 1

0

您是否使用文本作为这些字段的输入格式?从那里开始(/admin/structure/types/manage/[content_type]/fields)。

然后检查相关内容类型的管理显示选项卡 (/admin/structure/types/manage/[content_type]/display) 并确保您使用的是纯文本格式。

还要检查为应用于这些字段的文本格式启用的任何过滤器的过滤器处理顺序,屏幕位于 /admin/config/content/formats。

于 2012-08-01T14:40:04.400 回答