0

Drupal7のWebサイトに取り組んでいます。一部のページにカスタムレイアウトが必要です。だから私はpage--customContentTypeName.tpl.phpファイルを作成しました、そしてそれは完全にアドレスします。

問題は、ページtplにいくつかのフィールドを表示する必要があることです。以下のコードはノードtplで正常に機能しますが、ページtpl:/

<?php print $content['field_images']['#items']['0']['filename']; ?>" />

カスタムフィールドをページtplに呼び出すにはどうすればよいですか?

感謝します!! どうもありがとう!!


**ソート済み**

カスタムフィールド編集を使用...チュートリアルビデオは次のとおりです:http://lin-clark.com/blog/intro-drupal-7-theming-fields-and-nodes-templates#comment-54

4

3 に答える 3

2

構造は 7 で変更されました。フィールドは最初に言語によってキー設定されます (デフォルトでは「und」は「未定義」を意味します)。次に、次の例に従うことができます。

// Array of Image values
$images = $node->field_images['und'];

//If you don't know the language, the value is stored in:
$node->language


// First image
$image = $images[0];



// If you need informations about the file itself (e.g. image resolution):
image_get_info( $image["filename"] );


// If you want to access the image, use the URI instead of the filename !
$public_filename = file_create_url( $image["uri"] );


// Either output the IMG tag directly,
$html = '<img src="'.$public_filename.'"/>';

// either use the built-in theme function.
$html = theme(
    "image",
    array(
        "path" => $public_filename,
        "title" => $image["title"]
    )
);

Drupal 7 のファイル API は(CDN サービスとの統合を容易にするために) より抽象化されているため、ページに画像を埋め込むためuriに ではなく を使用することに注意してください。filename

于 2011-03-04T16:44:21.920 に答える
2

page.tpl.php の場合、ノードに直接アクセスする場合は $node 変数を使用できます

$node['field_images']['und'][0]['filename']

それ以外の場合は $page 変数を使用します。

$page['content']['system_main']['nodes'][1]['field_images']['#items'][0]['filename'];

ただし、ページ変数には複数のノードがある場合があることに注意してください。

于 2011-03-04T16:50:17.457 に答える