I have a custom template page called page-news.tpl.php. How do I create new pages for this template?

When I try creating new content ( Admin >> Create content >> Page) it creates a page based on the default page.tpl.php.

Somehow I need to tell Drupal that the new page created must be based on the page-news.tpl.php template.

thanks

C

Comments

nevets’s picture

Is the template meant to display just the one piece of content or different pieces of content?

ceci123’s picture

The template will display multiple blocks. I would have thought that creating new pages for my new template page-news.tpl.php was easy just like creating new pages for the default page.tpl.php. Anyway, I don't understand how having one or multiple content would matter.

I must be missing something something...

thanks

nevets’s picture

Templates are applied to existing content, they do not (or at least should not) determine what is show, only how the information is presented.

Blocks go in regions and you can control block visibility from the block configuration page.

The reason for the question about number of pages is will this template be applied to a single page of content or multiple pages of content has to do with a built in features. If you create some content (under create content) and give the content a path of 'news' then it will automatically use the page-news.tpl.php file.

ceci123’s picture

forgive me for I am still learning this system.

To repeat what you said, "If you create some content (under create content) and give the content a path of 'news' then it will automatically use the page-news.tpl.php file".

Wanted to do just that by going to Create content >> Page. But I dont' see where to enter the content path. I only see

Title:*
Menu link title: 
Parent item:
Body:
Input format:
Revision information:
Comment settins:
URL path settings: Automatic alias - checked. 
Authoring information
Publish options

Now. Under URL path settings I can uncheck the Automatic alias and enter the "?q=news" but this doesn't work.

Could you explain how to do this? pls. be gentle...one i learn it i won't ask again.

thanks again

c

nevets’s picture

On the correct path, you just want to use "news" (instead of "?q=news").

ceci123’s picture

I followed your directions and after the page is created it gets created using the DEFAULT page.tpl.php template file.

Believe me, I did it correctly. But for some reason it does not work.

I can see my page-news.tpt.php just find....i just can't seem to be able to create additional pages for the tpl.php file.

thanks again.

C

nevets’s picture

Opps, forgot you need this: http://drupal.org/node/139766

You will need to add the phptemplate_preprocess_page() function to your template.php (if your theme already as the function you will needto merge the two. (Note you want the Drupal 6 code)

ceci123’s picture

my template.tpl.php now contains this code:

<php
function phptemplate_preprocess_page(&$vars) {
  if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit','',$_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'] = array_merge((array) $suggestions, $vars['template_files']);
    }
  }
}
?>

When I < php print $ messages ;?> to display errors I receive this:

custompage could not find an appropriate theming function or template file for this path [news].
The viable options (in ascending priority) are:
    * 'phptemplate_news' in any module
    * 'THEMENAME_news' in a theme with the name THEMENAME
    * news.tpl.php template file in a current theme 

My page-news.tpl.php seems to be working...but I can't seem to be able to create new pages for this page-news.tpl.php theme. It always defaults to page.tpl.php.

Do I need to add some code to the function phptemplate_preprocess_page() above?

I am kind of stuck here.

thanks for your help.

C

nevets’s picture

This goes back to the question of how page-news.tpl.php works and when it is used.

As implemented it is aliased based. So pages with aliases like 'news', 'news/somepage', 'news/someotherpage' should end up on page-news.tpl.php while any other page would end up on page.tpl.php (the default).

What path are you using when you get the error (it does not make sense in the context of the code).

ceci123’s picture

nevets. Thanks for your explanation(...'news/somepage', 'news/someotherpage') i got it to work.

when creating content I had to create my own alias by unticking the Automatic alias option and write my own alias like this news/newspage1.

Thanks a lot for your help.

C

Anonymous’s picture

(I'm reading Leverage Drupal right now, and the phrase "more than one way to do it" keeps popping up.)

If it were me, I'd use the technique shown here:

http://drupal.org/node/249726

It's a little different approach from what you've been doing, but I've used it successfully in the past. It will depend on creating a new content type just for News.

Or you could edit the default page.tpl.php if all of your "pages" are going to be "news." Personally, I wouldn't do it that way. I'd do a new content type.

Hope that gives you some ideas,
Anne

ceci123’s picture

Here is the thing. The reason I starter to create "custom templates" is because my homepage, newspage, newsandeventspage, events page is structurely different. Eg. within the body, my newspage has two columns, the eventspage has one two rows with one column, and so on.

Read somewhere about using Panels...but didn't work. I must admit, I haven't worked a lot with content types so who knows this could be my savior.

Do you think I can do all these with content type.

I did read the link(http ://drupal.org/node/249726) you have provided. I could be wrong but it looks like for this to work you still have to create a template file, eg. page-nodetype-news.tpl.php which as stated "would apply to every page that displays a "news" node type."

I am still learning Drupal's behavior and i have learned a lot but seems that there lots more to go.

C

Ashraf Sufian’s picture

You can create a template called 'page-node-add-news.tpl.php' and put your code there so when you create a content of the type 'news' it will automatically open the new template.