Can some help me merge these two code samples

future assassin - May 2, 2008 - 14:45

I'm in need of having custom regions in my node-*.tpl.php files and found the following solution ( http://drupal.org/node/29139 ). Unfortunately I can't get it to work with the existing template.php file. Can someone merge these two for me.

This is from the above link

function _phptemplate_variables($hook, $variables) {
  // Load the node region only if we're not in a teaser view.
  if ($hook == 'node' && !$vars['teaser']) {
    // Load region content assigned via blocks.
    foreach (array('inline1') as $region) {
      $variables[$region] = theme('blocks', $region);
    }
  }
  return $variables;
}

And this is in my template.php file for switching templates

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':

      // Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page_about_history_early.tpl.php
      // page_about_history.tpl.php
      // page_about.tpl.php
      // Whichever is found first is the one that will be used.
      if (module_exists('path')) {
        $alias = drupal_get_path_alias($_GET['q']);
        if ($alias != $_GET['q']) {
          $suggestions = array();
          $template_filename = 'page';
          foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $suggestions[] = $template_filename;
          }
        }
        $vars['template_files'] = $suggestions;
      }
      break;

    case 'node':

      // Add node template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // node_about_history_early.tpl.php
      // node_about_history.tpl.php
      // node_about.tpl.php
      // Whichever is found first is the one that will be used.
      if (module_exists('path')) {
        $alias = drupal_get_path_alias($_GET['q']);
        if ($alias != $_GET['q']) {
          $suggestions = array();
          $template_filename = 'node';
          foreach (explode('/', $alias) as $path_part) {
            $template_filename = $template_filename . '-' . $path_part;
            $suggestions[] = $template_filename;
          }
        }
        $vars['template_files'] = $suggestions;
      }
      break;
  }

  return $vars;
}

Thanks in advance.

In your existing

nevets - May 2, 2008 - 15:13

In your existing template.php right before the last break

        }
        $vars['template_files'] = $suggestions;
      }
      break; // <<<<<

Add your other code like this
        }
        $vars['template_files'] = $suggestions;
      }

     // Load the node region only if we're not in a teaser view.
     if ( !$vars['teaser']) {
      // Load region content assigned via blocks.
      foreach (array('inline1') as $region) {
       $vars[$region] = theme('blocks', $region);  // Note $variables changed to $vars
      }
     }
      break; // <<<<<

Thanks nevets, Unfortunately

future assassin - May 3, 2008 - 03:14

Thanks nevets,

Unfortunately it doesn't seem to be working. I've set up a new section on the template.php file and the only other modification to the template.php file is what I posted here

I've changed foreach (array('inline1') as $region) { to reflect the name of my new section.

I've tried it with a stock page that uses node.tpl.php but still no go.

Any ideas?

I'm using 5.7

Thanks!

With out seeing to code or

nevets - May 3, 2008 - 03:42

With out seeing to code or know what not working means, no.

Looks like it was my fault

future assassin - May 3, 2008 - 06:33

Looks like it was my fault as I had the code in the template.php twice.

Thanks for the help.

 
 

Drupal is a registered trademark of Dries Buytaert.