0

I have a simple theme and everything is by documentation/examples:

function activit_theme() {

  return array(

      'activit_package_teaser' => array(
          'arguments' => array('node' => NULL),
          'type' => 'module'
      ),

  );
}

+

function theme_activit_package_teaser($node) {

  $output = '
    <div class="package-teaser">
      package  
    </div>
  ';

  return $output;
}

and

function activit_packages_block() {

  $nids = db_select('node', 'n')->fields('n', array('nid', 'status'));
  $nids->join('field_data_field_important', 'f', 'f.entity_id = n.nid');
  $nids->fields('f', array('field_important_value', 'entity_id'));
  $nids->condition('n.status', 1)->condition('f.field_important_value', 1);
  $nids = $nids->execute()->fetchCol();

  $nodes = node_load_multiple($nids);

  $packages = '';
  foreach($nodes as $node) {
    $packages .= theme('activit_package_teaser', array('node' => $node));
  }

  return '
    <div class="important-packages wrapper">
      <h2>'.t('Important packages').'</h2>

      <div class="cont">
        '.$packages.'
      </div>    
    </div>
  ';

}

there are 4 nodes, but my theme is not called at all and nothing is inserted into <div class="cont"></div>. No error in "recent log messages". Why it does not work?


UPDATE: When the template is in activit_package_teaser.tpl file it works:

  'activit_package_teaser' => array(
      'arguments' => array('node' => NULL),
      'template' => 'activit_package_teaser',
      'path' => drupal_get_path('theme', 'activit') . '/templates/',
  ),

But why it does not work as a theme function?

1 Answer 1

0

arguments was for Drupal 6, you need to use variables for Drupal 7. One of variables or render element is required, hence nothing is showing up at the moment as the item isn't making it into the theme registry.

function activit_theme() {

  return array(

      'activit_package_teaser' => array(
          'variables' => array('node' => NULL),
          'type' => 'module'
      ),

  );
}
4
  • That's weird because now I have the theme html in .tpl file and it works even if i still use arguments. Check update of my question.
    – Axel Stone
    Jun 29, 2017 at 9:22
  • Clear the caches, the changes won't be picked up until you do. It definitely shouldn't work with arguments if you have a non-modified Drupal 7 core, the docs say as much. If they're wrong it's a bug :)
    – Clive
    Jun 29, 2017 at 9:25
  • I cleared the cahce multiple times... I just checked my previous projects and realised that in every project I've made (D7) I used arguments and file template. It is the way I am used to. It allways worked. I also tried what you said - to use variables but it still just does not work when the theme is defined as a function theme_activit_package_teaser() :(
    – Axel Stone
    Jun 29, 2017 at 10:38
  • I also noticed than my custom module is in 'activit' folder and the same name has the folder where my theme is. Maybe that is the problem.
    – Axel Stone
    Jun 29, 2017 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.