これが問題です。
「ユーザーお気に入りブロック」というブロックがあります。
これは「最初のサイドバー」の領域に配置されてい
ます。「最初のサイドバー」がフロントページに表示されます。
この関数は、f25_favoritesテーブルからデータを取得し、それらをブロック内にリストすることになっています。現在、テーブルは空の配列です。
私return $output
の場合、divなどは何も出力されません。
するとprint($output)
、すべてが表示されます。
これは、「if」ステートメントがtrueを返していることを示すためのテストコードです。http://d.pr/zDph
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
dsm($mypaths);
print_r(count($mypaths));
$output .= 'n<div id="f25-favorites">n';
$output .= '<div id="f25-favorites-list">n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
print "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>n';
$output .= '<div id="f25-favorites-add">n';
$output .= '</div>n';
$output .= 'n</div>n';
return $output;
}
これはこれを出力します:http://d.pr/Uhrs
左上の0に注意してください。これは、「count()」の出力であり
、「if」内のテキストの出力です。
だから、これは私のテーマです:
/*
* f25_favorites_my_favorites theme
*/
function theme_f25_favorites_my_favorites($mypaths) {
/*dsm($mypaths);
print_r(count($mypaths));*/
$output .= '\n<div id="f25-favorites">\n';
$output .= '<div id="f25-favorites-list">\n';
if (count($mypaths) == 0) {
$output .= "No favorites have been added";
}
else {
foreach ($mypaths as $indpath) {
$output .= l($indpath->title, $indpath->path, $attributes = array());
}
}
$output .= '</div>\n';
$output .= '<div id="f25-favorites-add">\n';
$output .= '</div>\n';
$output .= '\n</div>\n';
return $output;
}
これは、次のhook_theme()関数で呼び出されます。
/*
* Implentation of hook_theme().
*/
function f25_favorites_theme () {
return array(
'f25_favorites_my_favorites' => array (
'arguments' => array ('mypaths' => array())
),
);
}
これは、このhook_block()関数で呼び出されます。
/*
* Implementation of hook_block().
*
*/
function f25_favorites_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks = array();
$blocks['f25-favorites'] = array(
'info' => t('User Favorites Block'),
'cache' => BLOCK_NO_CACHE,
);
return $blocks;
}
if ($op == 'view') {
switch ($delta) {
case 0:
$mypaths = f25_favorites_user_favorites();
$block = array(
'subject' => t('User Favorites Block'),
'content' => theme_f25_favorites_my_favorites($mypaths)
);
return $block;
};
}
}
注目に値する
私のテーマは「Zen」というテーマの「サブテーマ」です
。Zenには次のようなblock.tpl.phpがあります。http://d.pr/AaO1
これが私のモジュールの完全なコードです:http://d.pr/cGqc