ラベル

Server (108) work (77) Idea (68) Car (31) PC (29) DAW (28) other (19) MakingWEBsite (18) 趣味 (18) health (13) CentOS (11) drupal (11) 山 (9) android (4) スマホ (4) communication (3) drupal7 (3) hint (3) meno (3) モバイル (3) 歯医者 (3) 第二種電気工事士 (3) 英語 (3) PC Server (2) drupal8 (2) ms access (2) uwp C# (2) めし (2) 整備 (2) 音楽 (2) MIDI (1) diy (1) 会計 (1) 動画再生 (1) 生活 (1) 郵便 (1) 食べ物 (1)

2014年2月26日水曜日

drupal bartik フィールド値の抜き出し

フィールド値の抜き出し

bartikのテンプレート、node.tpl.phpの中に、こう書いてある。
$content: An array of node items. Use render($content) to print them all,
 *   or print a subset such as render($content['field_example']).

以下、その説明。
http://customfield.jp/tutorial/demo1/content/117
からの切取り。
(ここで言う
node--forrent.tpl.php
は、node.tpl.phpと思っていい。書き換える前のものを指しているので。)

----------------------------------------------------------------------------

node--forrent.tpl.php の中の、以下の部分を探してください。
<?php
  // We hide the comments and links now so that we can render them later.
  hide($content['comments']);
  hide($content['links']);
  print render($content);
?>

実は print render($content); の部分で、コンテンツの各フィールドを含む内容の出力をすべて担っています。変数 $content の中には表示すべき各フィールドの内容が含まれ、レンダー関数は子要素を再帰的にレンダリングするためです。特定のフィールドのみをレンダリングしたい場合は、
<?php print render($content['フィールド名']); ?>
のようにします。たとえば「敷金(field_deposit)」フィールドを表示したい場合は、
<?php print render($content['field_deposit']); ?>
となります。これを、いわゆるブログでいうところのテンプレートタグのように使い、あとはデザイン担当者が好きなようにHTML を使ってマークアップし、 <?php /* ~ */ print render($content); ?> の部分と置き換えてください。
----------------------------------------------------------------------------

0 件のコメント:

コメントを投稿