1

sites/all/modules/dc_wiwo

function dc_wiwo_theme($existing, $type, $theme, $path) {
  return array(
    'dc_wiwo_page' => array(
      'variables' => array('tweets' => array()),
      'template' => 'wiwo',
    ),
  );
}

function dc_wiwo_page() {
  return theme('dc_wiwo_page', array('tweets' => array()));
}

If I put a template file in sites/all/modules/dc_wiwo/wiwo.tpl.php it works, but if I put a file in sites/all/themes/media/wiwo.tpl.php it doesn't work. I thought you could override templates in the theme. Is there a setting I have to change to allow this?

  • I would imagine you would need mythemename_theme() or template_theme() or phptemplate_theme() in template.php for the theme to look at it just like you have in your module's file? – Jimajamma Dec 27 '11 at 16:08
  • I did this for a previous drupal 7 site, I am just wondering if anything needs to be enabled or if another module is interfering. – Chris Muench Dec 27 '11 at 16:14
  • It was because the folder my module was in is the same as my theme, which I think caused confusion and it still worked. – Chris Muench Dec 27 '11 at 16:18
  • that would do it...name space collisions... – Jimajamma Dec 27 '11 at 16:23
0

You should keep default template in module's directory in order to be able to override it in theme.

1

By default, the template file is expected to be in the same directory containing the module or the theme which defines the theme function. To use a different path, in the hook_theme() implementation you need to use the path property, which is defined as:

  • path: Override the path of the file to be used. Ordinarily the module or theme path will be used, but if the file will not be in the default path, include it here. This path should be relative to the Drupal root directory.

So, in your case the code should be similar to the following one, since you are using a theme.

function dc_wiwo_theme($existing, $type, $theme, $path) {
  return array(
    'dc_wiwo_page' => array(
      'variables' => array('tweets' => array()),
      'path' => drupal_get_path('theme', 'dc_wiwo') . '/media';
      'template' => 'wiwo',
    ),
  );
}

For a module, the code would not be much different.

function dc_wiwo_theme($existing, $type, $theme, $path) {
  return array(
    'dc_wiwo_page' => array(
      'variables' => array('tweets' => array()),
      'path' => drupal_get_path('module', 'dc_wiwo') . '/media';
      'template' => 'wiwo',
    ),
  );
}

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.