Does anyone know how this is done?

I want the page-blog.tpl.php file to change all the pages for each node within that content type and not just first page (www.example.com/blog). The first page is a view I’ve created and editing the page-blog.tpl file does change the layout – however it does not change each page for each node.

I’ve tried entering various sections of code into my template.php file to bypass the page.tpl.php file but I’ve had no success. The most recent code was this:

<?php
function framework_preprocess_page(& $vars) {
	if (isset ($vars['node']) && $vars['node']->type == "blog") {
		$vars['template_files'] = array();
		$vars['template_files'][] = 'page-blog';
	}

?>

It didn’t work, so I’m stuck. Any ideas?

Thanks

Comments

nanthony’s picture

I have a similiar issue that I have been trying to resolved. I created a page-story template to use for displaying stories rather that the default page template. I have tried multiple function calls in my template.php and nothing has worked...it keeps using the default template every time.

My ongoing issue is here: http://drupal.org/node/894176

I keep thinking I am missing something really basic to make this happen but it has had me stumped for a few days.

sovarn’s picture

Why don't you try changing the node.tpl.php instead.

Try creating a node-blog.tpl.php file.

joecanti’s picture

Not sure about the theming solution to this, but you could try the Panels module - its perfect for making different page templates per content type. Just enable the node template, and then add varients with selection rules: node type:yourcontenttype...

Makes it really easy to theme all your content types.

It can be a little slow with performance when using the flexible layout, but the standard layouts are great, and you can always hard code your flexible layouts when done.

Also the Panels everywhere module adds an interesting extra to this set up - you can completely do away with the page.tpl and blocks and theme you're whole site as panels by having one main site template panel.

I've noticed this to be really fast - faster even than garland theme or basic/framework etc with much less cross browser problems...

Joe

Boogle’s picture

I don’t like the code used with the panels module. I only use it for creating the odd page, like the front.

I already have a node-blog.tpl.php, that doesn’t let me change the page layout, it only lets you control the fields/content. I want to get into the main wrapper div but unfortunately that’s in the page.tpl.

zbricoleur’s picture

function phptemplate_preprocess_page(&$vars) {
  if ($vars['is_front'] != 1) {
    $vars['template_files'][] = 'page-' . $vars['node']->type;
    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;
        }
      }
    }
  }
}

This not only creates template suggestions based on content type (which, as you note, doesn't help for blog entries), it also creates them based on the URL alias (so page-blogs.tpl.php could work for the blog entry pages if you use the pathauto module and set the default path for blog entries to blogs/[author-name-raw]/[title-raw]). It also solves the problem with the front page that someone mentioned.

Boogle’s picture

Doesn’t work for me. I did exactly what you said. I’d already tried setting the URL aliases with Pathauto. Tried it with several different variants of your code but no luck I’m afraid. I’m curious to know if anyone has successfully done this because I can’t find anything on the internet solving this problem.

Thanks anyway.

zbricoleur’s picture

Yes, someone has successfully done it. I've done it, using the instructions I just offered. Lots of other people have done it, too. You're doing something wrong, but without more information, it's hard to say what.

Boogle’s picture

My apologies zbricoleur, I was indeed doing something wrong. It works perfectly. Thanks for your assistance.

zbricoleur’s picture

Glad to hear it's worked out. For the benefit of others who may read this in the future, could you tell us what the problem was?

emilflatz’s picture

Just used your function on my custom theme and it works great!

phaktza’s picture

Thanks, saved me hours of searching and building my own solution.

dileepunni1’s picture

For me it is working for the blog content types
because we are customized blog templates with a custom module and different template files used for each blogger
.So in blog detail page (ie.node) it automatically fall backs to a view with a path node/%.Then i used above template sysetm for load my page template from alias.So i will remain on blog page when we show detail of each blog and viceversa

thanks for your snippet

Anthony Pero’s picture

Anyone know what the Drupal 7 code would look like for this?

Anthony Pero
Project Lead
Virtuosic Media
http://www.virtuosic.me/