Frage

I'm using Drupal 7 and have created a custom module named fb. In the fb.module file, I have the following:

function fb_theme($existing, $type, $theme, $path) {
  return array(
    'fb' => array(
      'template' => 'fb'
    )
  );
}

In the same directory as the module file (the module's root), I have a file named fb.tpl.php that contains:

fb.tpl.php is working!

For testing purposes, my theme's html.tpl.php file calls the following in the body:

<?php
$ouput = theme('fb');
print_r($output);
?>

However, the print_r($output) line doesn't produce anything. I expect it to contain the contents of the fb.tpl.php file, or perhaps an array that contains the contents of that file as the value to one of its parameters. Why doesn't it?

War es hilfreich?

Lösung

You don't need to use the theme function at all in Drupal 7. Instead, create a renderable array like this:

$output = array(
  '#theme' => 'fb'
);

And output it like this:

drupal_render($output);

That would be the easiest way to output it in your html.tpl.php file.

Andere Tipps

You are using the drupal 6 syntax. the D7 syntax is as follows:

function fb_theme($existing, $type, $theme, $path) {
  return array(
    'fb' => array(
      'file' => 'fb'
    )
  );
}

See the full documentation here: http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_theme/7

[edit] - also dont forget to flush the theme cache after you make changes to the theme hooks, otherwise you wont see the changes.

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