Fix for load node.tpl.php by path

  1. function blueprint_preprocess_node(&$vars) {
  2.   // template name for current node id
  3.   $suggestions = array('node-'. $vars['nid']);
  4.   // additional node template names based on path alias
  5.   if (module_exists('path')) {
  6.     // we already can have a path alias
  7.     if (isset($vars['path'])) {
  8.       $alias = $vars['path'];
  9.     }
  10.          
  11.     else {
  12.       // otherwise do standard check
  13.  
  14.       $alias = drupal_get_path_alias('node/'. $vars['nid']);
  15.     }
  16.     if ($alias != 'node/'. $vars['nid']) {
  17.       $add_path = '';
  18.       foreach (explode('/', $alias) as $path_part) {
  19.         $add_path .= !empty($path_part) ? $path_part : '';
  20.         $suggestions[] = 'node-'. $add_path;
  21.       }
  22.       // adding the last one (higher priority) for this path only
  23.       // node-some-long-path-nofollow.tpl.php (not for anchestors)
  24.       $suggestions[] = end($suggestions) .'-nofollow';
  25.     }
  26.   }
  27.   $vars['template_files'] = isset($vars['template_files']) ? array_merge($vars['template_files'], $suggestions) : $suggestions;
  28. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.