Skip to main content
Notice removed Draw attention by jcisio
Bounty Ended with paul-m's answer chosen by jcisio
Add a full example
Source Link
jcisio
  • 1.4k
  • 1
  • 14
  • 25

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }'node__test';
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach') . '/themes';
  $theme_registry_copy = $theme_registry;
  _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'node', drupal_get_path('module', 'node'));
  $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
  if (!isset($theme_registry['node']['theme paths'])) {
    $theme_registry['node']['theme paths'] = array($path);
  }

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter if (&$theme_registry!isset($theme_registry['node']['theme paths'])) {
  // Put the$first_element themes= folderarray_shift($theme_registry['node']['theme atpaths']);
 the lowest priority soif that($first_element) themes{
 can override it.
  // Attention:array_unshift($theme_registry['node']['theme itpaths'], seems$first_element, that$path);
 advanced_forum removes the first}
 path, so we'll beelse safe{
 to be the 2nd.
  array_splicearray_unshift($theme_registry['node']['theme paths'], 1,$path);
 0, drupal_get_path('module', 'attach')); }
  }
}

Edit 3/21: solution like http://drupal.org/node/715160However it does not work. That means: the file themes/node--super.tpl.php is not used. It is used only if I copied it to the theme folder.

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}

Edit 3/21: solution like http://drupal.org/node/715160 does not work.

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  $vars['theme_hook_suggestions'][] = 'node__test';
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach') . '/themes';
  $theme_registry_copy = $theme_registry;
  _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'node', drupal_get_path('module', 'node'));
  $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
  if (!isset($theme_registry['node']['theme paths'])) {
    $theme_registry['node']['theme paths'] = array();
  }
  if (!isset($theme_registry['node']['theme paths'])) {
    $first_element = array_shift($theme_registry['node']['theme paths']);
    if ($first_element) {
      array_unshift($theme_registry['node']['theme paths'], $first_element, $path);
    }
    else {
      array_unshift($theme_registry['node']['theme paths'], $path);
    }
  }
}

However it does not work. That means: the file themes/node--super.tpl.php is not used. It is used only if I copied it to the theme folder.

Tweeted twitter.com/#!/StackDrupal/status/182660645437718529
added 73 characters in body
Source Link
jcisio
  • 1.4k
  • 1
  • 14
  • 25

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}

Edit 3/21: solution like http://drupal.org/node/715160 does not work.

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}

Edit 3/21: solution like http://drupal.org/node/715160 does not work.

Notice added Draw attention by jcisio
Bounty Started worth 50 reputation by jcisio
added 404 characters in body
Source Link
jcisio
  • 1.4k
  • 1
  • 14
  • 25

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:

function attach_preprocess_node(&$vars) {
  if (($vars['view_mode'] === 'attach' || $vars['view_mode'] === 'attach_ajax')) {
    $vars['theme_hook_suggestions'][] = 'attach__node__default';
    $vars['theme_hook_suggestions'][] = 'attach__node__' . $vars['type'];
  }
}

(I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node__attach__% to avoid confusion with node type.)

Then I use hook_theme_registry_alter() to add module path:

function attach_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'attach');
  $theme_registry['node']['theme paths'] = array($path);
}

However it does not work. I even tried a minimal example: use hook_theme_registry_alter() to add path to $theme_registry['node']['theme paths'] then place a node.tpl.php in the module folder, but I failed to make it work.

Edit: in D6 the below code works

function attach_theme_registry_alter(&$theme_registry) {
  // Put the themes folder at the lowest priority so that themes can override it.
  // Attention: it seems that advanced_forum removes the first path, so we'll be safe to be the 2nd.
  array_splice($theme_registry['node']['theme paths'], 1, 0, drupal_get_path('module', 'attach'));
}
Source Link
jcisio
  • 1.4k
  • 1
  • 14
  • 25
Loading