这就是问题所在。
我有一个名为“用户收藏块”
的块,它位于“第一个侧边栏”
“第一个侧边栏”出现在首页上的区域。
该函数应该从 f25_favorites 表中获取数据并将它们列在块中。现在该表是一个空数组。
当 Ireturn $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