4

Well, here is the problem. In my site I want to create a plain template and add my own regions and my own blocks. So when the user visits for example www.example.com/register-now the blocks will be different from the main page. I dont like disabling the blocks because when you open Firebug the blocks can be still be seen.

So I have read in this article that you have to create a new .tpl.php file. So in my case I created the page__register-now.tpl.php file. and put that under drupal/sites/all/themes/ninesixty/ directory.

Then I opened the template.php file and tried the below code:

function ninesixty_preprocess_page(&$vars, $hook) {
  $path=drupal_get_path_alias();

  if($path == 'register-now'){
    $variables['theme_hook_suggestion'] = 'node__register';
  }
}
5

If your path to the register page is www.example.com/register-now then you only need to name the page template file appropriately and Drupal should do the rest, you shouldn't need to add anything to template.php.

From what you've written, the name of the page template file is wrong. It needs to be renamed to: page--register-now.tpl.php (notice the underscores turned to dashes).

After you rename the file (usually after adding any additional template files), make sure to clear all caches from admin/config/development/performance.

EDIT: If your page is a node, you can't use the Alias path in the template file, it actually has to be the internal path to the node, e.g. page--node--123.tpl.php where 123 is your node's ID.

The rest are based on the internal path of the current page. Do not confuse the internal path to path aliases which are not accounted for.

See here

  • Ok i see. So i don't need to add anything to my tempate.php file. I will remove the inputted code then from my template.php file and try that again. – paranod Jul 5 '12 at 10:17
  • ok I renamed the file to page--register-now.tpl.php remove the code added to template.php and clear the cache and saved the configuration. After that, i clicked on content and created a new basic page and added the html code for the display, entered tha url path alias as register-now and nothing happened. Is this because i am creating the page through the content tab and drupal gets the page.tpl.php theme ??? – paranod Jul 5 '12 at 11:03
  • Right, if your page is a node, it actually has to have the internal path, e.g. node/24 in the template file name. So find out your node's ID (hover over the edit link and it should say node/24/edit where 24 is your node id. Then name your page template file as page--node--24.tpl.php replacing 24 with your actual node's id. – Beebee Jul 5 '12 at 11:43
  • Frustrating but GENIUS. Millions of thanks:):) – paranod Jul 5 '12 at 11:55
  • One last question for a multilingual site is there a way to create just one page--node--24.tpl.php file?? Or maybe add some conditions to the template.php file?? – paranod Jul 5 '12 at 12:24

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.