Hi all,

I have created a content type called "static page," which I plan to use for something different than the normal "page" content type.

I want to give the Static Page content a completely different layout than the Page content.

I read about creating a node-static.tpl.php file, and I did, but this doesn't seem to let me change the whole layout in the same way that the page.tpl.php file does.

I tried creating a page-static.tpl.php file, but that doesn't seem to do anything.

Any suggestions? Thanks!

Comments

JonMB’s picture

Note: I know I can create a page.tpl.php file for each specific node, but that is very tedious and inefficient for hundreds of pages. I want to be able to apply everything to a new content type instead.

amariotti’s picture

Contemplate allows for some incredible customization of full nodes, teasers, and RSS feeds on a per-content-type basis.

JonMB’s picture

@amariotti, thanks for your suggestion. I may end up using that, but is there not a simple non-Module approach?

I just tried creating a "page-node-static.tpl.php" file, but that does nothing. Then I created "page-node-43.tpl.php" and that does work, but this is calling the specific node id instead of its content type. Like I said earlier, this would be bad if I have hundreds of pages.

WorldFallz’s picture

You can create any manner of template files you need, see: Working with template suggestions.

Another option is the panels module, see: Panels 2: Create a node override

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

JonMB’s picture

Ah, perfect. Thanks very much. I'm surprised I didn't find that myself!

WorldFallz’s picture

welcome ;-)

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

JonMB’s picture

I'm having an issue creating more than one, though. Using the suggesting from the link Working with template suggestions, I added this to my template.php file:

<?php
function my_theme_preprocess_page(&$variables) {
  if ($variables['node']->type == "my_content_type") {
    $variables['template_files'][] = 'page-node-my_content_type';
  }
}
?>

And this works fine for one content type. But I have four content types I want to theme, so I tried adding it in four times.

<?php
function my_theme_preprocess_page(&$variables) {
  if ($variables['node']->type == "my_content_type1") {
    $variables['template_files'][] = 'page-node-my_content_type1';
  }
}
?>

<?php
function my_theme_preprocess_page(&$variables) {
  if ($variables['node']->type == "my_content_type2") {
    $variables['template_files'][] = 'page-node-my_content_type2';
  }
}
?>

<?php
function my_theme_preprocess_page(&$variables) {
  if ($variables['node']->type == "my_content_type3") {
    $variables['template_files'][] = 'page-node-my_content_type3';
  }
}
?>

<?php
function my_theme_preprocess_page(&$variables) {
  if ($variables['node']->type == "my_content_type4") {
    $variables['template_files'][] = 'page-node-my_content_type4';
  }
}
?>

Now I receive this error when trying to load my site: Fatal error: Cannot redeclare newsflash_preprocess_page() (previously declared in /home/www/drupal/themes/newsflash/template.php:123) in /home/www/drupal/themes/newsflash/template.php on line 133

Any ideas? How do I theme multiple content types, instead of just an additional one?

JonMB’s picture

Nevermind. For some reason in my fairyland head I seem to think I can repeat functions. For anyone wondering, this is the correct code to use if you have multiple content types:

<?php
function newsflash_preprocess_page(&$variables) {
  if ($variables['node']->type == "static") {
 	  $variables['template_files'][] = 'page-node-static';
  } elseif ($variables['node']->type == "news") {
  	  $variables['template_files'][] = 'page-node-news';
  } elseif ($variables['node']->type == "codes") {
  	  $variables['template_files'][] = 'page-node-codes';
  } elseif ($variables['node']->type == "jokes") {
  	  $variables['template_files'][] = 'page-node-jokes';
  } 
}

?>

Notice the different content types I have: news, static, jokes, codes.

WorldFallz’s picture

lol, good job ;-)

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

markosef’s picture

just what i needed now, community is great. if only experts were more involved, seems that i find good solution often that are dug out by non-experts :-)

interestingaftermath’s picture

I have a content type (machine name): article / Zen subtheme name: tdl / tpl file: page-node-article.tpl.php

I cannot seem to get this working. Here's what I have in my sub themes template file:

function tdl_preprocess_page(&$variables) {
  if ($variables['node']->type == "article") {
    $variables['template_files'][] = 'page-node-article';
  }
}

I am trying to them all article node pages. Here's an example of the page I want to theme: http://davianletter.com/tdl/articles/test-article

WorldFallz’s picture

Trying copying the page.tpl.php file from the main theme into the subtheme's directory as well-- then clear the cache.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

amariotti’s picture

Ryan, I love that theme! Way to go. Interested in giving it back to the community any time soon? ;)