开发者

Drupal7: Trying to theme a specific page using a preprocess function, but...I get a blank screen instead

I've just discovered that if you want to alter a specific page (or group of pages) all you need is to add templates file to the core templates. For instance, I need to theme my /helloword page using a page--helloworld.tpl.php and node--helloworld.tpl.php template files.

Now all I get is a blank screen so I tried to write a preprocess function that adds support for custom theme files like:

<?php
/**
* Adding or modifying variables before page render.
*/
function phptemplate_preprocess_page(&$vars) {

  // Page change based on node->type
  // Add a new page-TYPE template to开发者_如何学Go the list of templates used
  if (isset($vars['node'])) {
    // Add template naming suggestion. It should alway use doublehyphens in Drupal7.
    $vars['template_files'][] = 'page--'. str_replace('_', '-', $vars['node']->type);   
  }
}
?>

I see no syntax error but I still get a blank screen. Still no luck

Is someone able to figure out what's wrong in the code/routine?

Drupal7 + Omega Sub-Theme

Kind Regards


I think there's a tiny bit of confusion here: a template file named node--type.tpl.php will automatically be called for any node which has the type type...you don't need to add the template suggestions in yourself.

There is one caveat to this, you have to copy the original node.tpl.php to your theme folder and clear your caches otherwise Drupal won't pick it up.

Also you don't want to use the phptemplate_ prefix...rather you want your function to be called MYTHEMENAME_preprocess_page.

Your code to add the page template based on the node type looks spot on, see if you still have the problem after you change your function name and clear the caches.

Hope that helps :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜