0

I am developing a site using drupal. I need to create a template file for a specific page. For instance this is my site url http://www.dev.com. I created a basic page called documents which URL path settings alias is docs. So what I want to do is that whenever the user clicks on http://www.dev.com/docs drupal should use a specific template file. For that matter I create a tpl file called page--docs.tpl.php and put it inside my theme folder. However drupal seems not loading that file.

PLease assist me if I am missing something.

6
  • have you cleared the cache ?
    – Bala
    Commented Feb 25, 2014 at 11:48
  • Yes I have cleared the cache.
    – Arsene
    Commented Feb 25, 2014 at 11:49
  • What is the non-aliased path?
    – rooby
    Commented Feb 25, 2014 at 11:52
  • have you added this in your template.php file function nexus_preprocess_page(&$vars) { if (isset($vars['node'])) { // If the node type is "blog" the template suggestion will be "page--blog.tpl.php". $vars['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $vars['node']->type); }
    – Bala
    Commented Feb 25, 2014 at 11:53
  • @Bala I have not added that code.
    – Arsene
    Commented Feb 25, 2014 at 11:55

4 Answers 4

2

You need to use the non-aliased path for the template name.

For example if you are dealing with node 1 (node ID = 1) try naming the file page--node--1.tpl.php and clearing the cache again.

For more info see: https://drupal.org/node/1089656#page-suggestion

If you don't know what the node id is, go to the node edit page and it will be in the url /node/NODEID/edit.

5
  • Please robby do I need to add the code suggested by Bala?
    – Arsene
    Commented Feb 25, 2014 at 11:59
  • No, not to have a page template for 1 specific node. His code would allow you to have a template for all nodes of a particular node type.
    – rooby
    Commented Feb 25, 2014 at 12:00
  • @robby : I did as you suggested but the page rendered blank.
    – Arsene
    Commented Feb 25, 2014 at 12:03
  • Are there any errors in your web server logs? Often a white screen will mean there is an error in the code of your template. Try with a direct copy of the normal page template with just a minor change like some extra text in the page title or something. Then once it is working make the change you want.
    – rooby
    Commented Feb 25, 2014 at 12:04
  • Thank you all. It is working now. I did as suggested by robby.
    – Arsene
    Commented Feb 25, 2014 at 14:00
0

To quickly and efficiently find the name to call your template add the following

$conf['theme_debug'] = TRUE;

to you your settings.local.php this will add a comment block before the rendering of your data

<!-- THEME DEBUG -->
<!-- CALL: theme('node') -->
<!-- FILE NAME SUGGESTIONS:
 * node--419.tpl.php
 x node--standard-content-page.tpl.php
 * node.tpl.php
-->

for example the above block tells me that if I want to just theme for that one object use the "node--419.tpl.php" for the filename but I chose to make the theme edit available for all objects of the type "standard_content_page"

Ado

0

You should try using the page theme module it does exactly what you're looking for using drupal configuration and there's a stable version for drupal 7.

-1

you can also overwrite the template in template.php as well

function themeName_preprocess_page(&$vars, $hook) {
$vars['template_files'][] = 'page--docs';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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