Frage

This is the issue.

I have a block called 'User Favorites Block'
It's placed in the region 'First Sidebar'
'First Sidebar' appears on the front-page.
The function is supposed to grab the data from the f25_favorites table and list them inside the block. Right now the table is an empty array.
When I return $output, none of my divs or anything are output.
When I do print($output), everything is displayed.

This is my test code to show that my 'if' statement is returning 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;
}

This outputs this: http://d.pr/Uhrs
IF test

Note the 0 on the top left, that's the output of the 'count()'
And the print of the text within the 'if'

So, this is my theme:

/*
 * 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;
}


It's called with this hook_theme() function:

/*
 * Implentation of hook_theme().
 */
function f25_favorites_theme () {
  return array(
    'f25_favorites_my_favorites' => array (
    'arguments' => array ('mypaths' => array())
   ),
  );
}


Which is called with this hook_block() function:

/*
 * 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;
    };
  }
}

Noteworthy

My theme is a 'Sub-theme' of a theme called 'Zen'
Zen has a block.tpl.php which looks like this: http://d.pr/AaO1

Here is the full code of my module: http://d.pr/cGqc

War es hilfreich?

Lösung

It could be a region-related problem. Try switching to Garland and add the block to a plain old Garland region, and see if it appears.

If you see it in Garland then make sure your sub-theme really is defining that "First Sidebar" region and then actually printing its variable in the tpl files.

(FWIW I tried your code on Garland and it displays the block fine.)

Also, you might want to change your function call from:

theme_f25_favorites_my_favorites($mypaths)

to:

theme('f25_favorites_my_favorites', $mypaths)

...if you want to keep the code flexible (i.e. have Drupal call any preprocess functions and allow other people, or yourself in the future, to override the template's output)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top