0

I create page--hospital.tpl.php file. To call this page, then I create Basic Page and Page title is "Hospital". I provided on the Menu Link and I typed "hospital" in URL path alias. Then, Save the file.

The problem is that when I click on the "Hospital" menu link it only shows the basic page content and it doesn't show up my page--hospital.tpl.php file. Please,help me !

Thanks.

2
  • I also renamed the page--hospital.tpl.php page into "page--node--7.tpl.php". However, it also has a problem because giving the nodeid to the pagename makes not flexible. If I deploy in other PC, and create Basic Page , then it does not same the nodeid. I also don't want to export my database and import to other database
    – May Phyu
    Dec 30 '14 at 10:30
  • In that case I suggest you create a new content type that has similar fields to basic page. Then you override node.tpl.php with node--type.tpl.php where type is the machine name of your new content type. This will then be exportable in a flexible way. Also look at 'Add a page.tpl.php depending on content type.' section on doc page on how to do custom theme suggestions via a preprocess function. Dec 30 '14 at 10:30
4

To understand how to use Theme Hook Suggestions, please refer to the documentation at: Drupal 7 Template (Theme Hook) Suggestions

node--[type|nodeid].tpl.php

base template: node.tpl.php

Theme hook suggestions are made based on these factors, listed from the most specific template to the least. Drupal will use the most specific template it finds:

node--nodeid.tpl.php

node--type.tpl.php

node.tpl.php

page--[front|internal/path].tpl.php

base template: page.tpl.php

The suggestions are numerous. The one that takes precedence is for the front page. 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. Keep in mind that the commonly-used Pathauto module uses path aliases.

The front page can be set at "Administration > Configuration > System

Site information." In Drupal 6, at "Administrator > Site configuration > Site information." Anything set there will trigger the suggestion of "page--front.tpl.php" for it.

The list of suggested template files is in order of specificity based on internal paths. One suggestion is made for every element of the current path, though numeric elements are not carried to subsequent suggestions. For example, "http://www.example.com/node/1/edit" would result in the following suggestions:

  1. page--node--edit.tpl.php

  2. page--node--1.tpl.php

  3. page--node.tpl.php

  4. page.tpl.php

It can be done in a variety of ways (at the page level as well). You can also provide your own suggestions in a preprocess function.

In your case you have not defined a new content type, but have used the Basic Page type, and you want to do it for a single page only. You therefore need to get the node id of your page, and then override as follows:

node--nodeid.tpl.php

or

page--node--nodeid.tpl.php

In your case, as you indicated that you wish to override the page.tpl.php file, it will be the latter.

0

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.