0

Hi I want to create an article then define a alias path for it then change template of that page. For example I add an article with title "categories" and no other content like body or image. Then I define "categories" alias for it. Now when I add "page--categories.tpl.php" in my theme template folder nothing happened to page http://example.com/categories and I just see a white page in content region.

0

The main issue is that templates rely upon the system path, not the alias.

So, while you are surfing to categories on your system, Drupal still really sees that as node/### in your case.

All is not lost, however, as there are several avenues available to you:

If you know the nid of the article, you can create a template for it like so:

page--node--###.tpl.php

eg

page--node--123.tpl.php

and no matter what the alias, Drupal will use this template when displaying that node.

If you don't know, or it might for whatever reason change later, but the title will always be the same, you can do something like this:

YOUR_DRUPAL7_MODULE_OR_THEME_preprocess_page(&$variables) {

   if (!empty($variables['node']) && $variables['node']->title=='Categories') {
     $variables['theme_hook_suggestions'][]='page__categories';
   }

}

Further reading and a lot more information on this can be found here:

https://drupal.org/node/1089656

and here:

https://drupal.org/node/223440#custom-suggestions (includes Drupal 6 methods as well)

1
  • Hi thanks I think that the first way is better than the second because maybe there is another page titled as this page. I solve my problem with combine your ways and in the theme_preprocess_page function check for the nid and name the template file page--categories. Thanks again. – Saeed Rajabi Jul 25 '13 at 15:29
0

Refer this url http://drupalknowledge.blogspot.in/2012/01/different-page-template-for-different.html

You can print $vars['node'] variable and get the particular node path to give different template.

I hope this will help you.

1
  • Thanks for your reply I solve the problem in another way. In the theme_preprocess_page function check for the nid and name the template file page--categories. – Saeed Rajabi Jul 25 '13 at 15:32
0

The new version of drupal should be able to do this automatically for you. Just copy page.tpl.php and rename it to page--node.tpl.php or page--category.tpl.php and then head to /admin/config/development/performance and clear the cache then refresh your site the new custom page should be loaded and ready for customization to your liking

-1

In template.php theme_preporcess_page() if this fuction exist in template.php otherwise you need to create it .

then function themename_preprocess_page($variables) { you need to print_r($variables); }

for node you can do similar function themename_preprocess_node($variables) ;

then this array find [theme_hook_suggestions] variable .here in array given page template suggestions ..

1
  • Thanks for your reply I solve the problem in another way. In the theme_preprocess_page function check for the nid and name the template file page--categories. – Saeed Rajabi Jul 25 '13 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.