2

sys info: drupal 6 installation, with tons of modules... too many to list.

the problem: only a certain content type will not load it's template file correctly. some nodes that would be displayed on these pages through views are making it to the markup. they are the only content that gets loaded. the template file that this content falls back on is node-event.tpl

the objective: to load page-team.tpl.php

template suggestions are loaded in two ways in template.php through preprocessing via

mytheme_preprocess_page(&$vars, $hook)

converted from _phptemplate_variables () in a drupal 5 installation.

method 1:

if (module_exists('path')) {
  $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
  if ($alias != $_GET['q']) {
    $template_filename = 'page';
    foreach (explode('/', $alias) as $path_part) {
      $template_filename = $template_filename . '-' . $path_part;
      $vars['template_files'][] = $template_filename;
    }
  }
}

method 2:

if ($vars['node']->og_groups['0'] || preg_match('/fdl\//',$vars['node']->path) || (preg_match('/og\/manage/',$alias) || preg_match('/og\/invite/',$alias) || preg_match('/og\/users/',$alias)) || (preg_match('/node\/add/',$alias) && $_GET['gids'] != '') || $vars['node']->og_description || (arg(0) == 'user' && is_numeric(arg(1)))) { 
  $vars['template_files'][] = 'page-team';

}

page-team is the tpl that is missing, and i suspect there may be an error with my code above (method 2).

i'm attempting to load this template for all pages with the first path argument of "fdl" so site.com/fdl and all children of fdl.

i know there are lots of possibilities. but i have a feeling the error is here. thanks for any help you can offer.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Matt Ryan
  • 1,717
  • 2
  • 20
  • 30
  • Does your theme folder already contain page.tpl.php? There is a known bug (http://drupal.org/node/279573) which says that node-foo.tpl.php cannot be used by a theme when node.tpl.php is not available. The same might apply to page.tpl.php - I'm not 100% sure. – marcvangend Aug 30 '10 at 08:58
  • thanks for your reply, but i do indeed have page.tpl.php in the theme directory. – Matt Ryan Aug 30 '10 at 15:15

4 Answers4

1

Well, did you clear cache? Because when dealing with themes, drupal usually catches newly added themes and templates after clearing cache.

And if you are not sure about your reg. exp., i believe you can simply write this:


if(strpos(drupal_get_path_alias($_GET['q']),'fdl')===0){
    $vars['template_files'][] = 'page-team';
}

And clear cache.

angryobject
  • 418
  • 2
  • 7
  • i had cleared cache, to no avail. thank for your snippet, but no luck there either. the page still loads only the node template and not the page template. – Matt Ryan Aug 30 '10 at 15:22
  • It should work. I have just tested it in my project. See below the whole example. – angryobject Aug 30 '10 at 20:29
1

This is what i have in my template.php:


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

frontend is the name of my theme. I have a file page-dummy.tpl.php inside the theme folder. To see that it works i added "IT WORKS" right after the body tag. Then cleared cache. Now i go to page "mydomain.com/dummy_tests/1" and see that IT WORKS.

If you are having problems, try to check the output of drupal_get_path_alias($_GET['q']). Just do


print drupal_get_path_alias($_GET['q']);

right inside the preprocess_page() function. And if it really starts with "fdl" everything should work. This is a working example, so you just try to play around and figure out why it's not working for you.

BTW, try to remove the node template and leave only the page template. I don't know why, but may be something is wrong and drupal messes them.

angryobject
  • 418
  • 2
  • 7
  • yeah, the query is correct, but still the page tpl is not loading. you think because it is a custom content type there is an issue? – Matt Ryan Aug 30 '10 at 20:46
  • Not really. I dont think a custom content type could make something wrong. And i just cant figure out why this is not working for you. – angryobject Aug 30 '10 at 21:12
  • so strange, by removing the node template the page template was available. i would still like to know what exactly gave the node precedence but, thanks for your help angry. – Matt Ryan Aug 31 '10 at 02:40
  • If this is the case, then propably the node template somehow appears to be the last element of the $vars['template_files'] array. Because templates are applied in the reverse order they go in this array. But yep, this is still stange. And i never faced this before somehow. I think i'll try to create both the node and the page templates and see wheather it works. – angryobject Aug 31 '10 at 04:34
  • yes, but I need both. the page and the nodes on it to be templated – Matt Ryan Aug 31 '10 at 18:13
  • I'm sorry for being away for so long, just had a lot of work to do. But i tried something and it worked. See the answer below. If if will not work for you... Well, i even don't know how else to help( – angryobject Sep 06 '10 at 09:20
0

I tried adding custom templates in both page_preprocess and node_preprocess functions. And it worked both for page and node templates for me.


function frontend_preprocess_page(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'page-dummy';
  }
}

function frontend_preprocess_node(&$vars){
  if(strpos(drupal_get_path_alias($_GET['q']),'dummy_tests')===0){
      $vars['template_files'][] = 'node-dummy';
  }
}

angryobject
  • 418
  • 2
  • 7
0

i found a deprecated link function in the template. updating the parameters fixed everything.

Matt Ryan
  • 1,717
  • 2
  • 20
  • 30