I found a snippet somebody posted online, that I'm trying to use to solve a quick problem, but it didn't seem to do anything.

Essentially I have pages that are different translations of the same page. I'd like to have all of them use the same template, currently node--12345.tpl.php , for example.

The code:


function phptemplatevariables($hook, $vars = array()) {
  switch ($hook) {
    case 'page': if((arg(0)=='node') && ((arg(1) == '12345') || (arg(1) == '19261'))) {
         $vars['template_files'] = 'node--12345';
      }
    }
  return $vars;
} 

I've gotta be pretty close. Seems close anyway.

EDIT: I should add - I thought this would work automatically in D7, but I think, because I've got some ajax to these specific pages it's not working? I could be wrong. Just wanted to clarify.

Comments

Jaypan’s picture

I don't see how that code would ever have worked - maybe it was a D6 or D5 thing? But you are partially right that ajax has something to do with it - this bit here would never work in an ajax call:

if((arg(0)=='node')

With ajax calls, arg(0) will never be 'node'.

The following should do what you want:

function HOOK_preprocess_node(&$vars)
{
  if(in_array($vars['#node']->nid, array(12345, 12346, 12347, ...)))
  {
    $variables['theme_hook_suggestions'][] = 'node__12345';
  }
}

Three things:
1) You'll need to change the function name accordingly to pick up the hook.
2) Replace the NIDs in array(12345, 12346, 12347, ...) with your actual NIDs.
3) I'm not entirely sure that the node object is at $vars['#node']. You may have to examine $vars to find where it is.