2

In a module I created, can I add a call to theme() similar to theme('example_def', $var) where example_def is a theme function defined from another module?

function def_theme() {
return array(
  'example_def' => array(
    'arguments' => array('nid' => NULL)
  ));
}

function theme_example_def() {}
2

Yes, a module can call, with theme(), a theme function that is defined from another module. If it were not so, no module could use theme_link(), since that is defined as one of the System module theme functions. This is contrary to Drupal philosophy; limiting a module to use the theme functions it defines would not make sense.

See system_theme() which calls drupal_common_theme() to add link to the theme function it implements.

function drupal_common_theme() {
  return array(

    // From theme.inc.
    'html' => array(
      'render element' => 'page',
      'template' => 'html',
    ),
    'page' => array(
      'render element' => 'page',
      'template' => 'page',
    ),
    'region' => array(
      'render element' => 'elements',
      'template' => 'region',
    ),
    'status_messages' => array(
      'variables' => array('display' => NULL),
    ),
    'link' => array(
      'variables' => array(
        'text' => NULL,
        'path' => NULL,
        'options' => array(),
      ),
    ),
    // …
  );
}

Notice that the correct theme function definition that works for Drupal 7 is the following one; the one you are using is only for Drupal 6 or previous versions.

function def_theme() {
  return array(
    'example_def' => array(
      'variables' => array('nid' => NULL)
    )
  );
}

Since your example of calling the function is theme('example_def', $var), I take you are using Drupal 7, for which your definition would not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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