Our custom theme has page.tpl.php which takes care of the whole site. But I have a page which actually needs to display a collection of nodes. I have written a custom page--url.tpl.php where the url is the path for the page in question. But this way overrides the whole page.tpl.php.

What would be best method so that I just need to display my custom content when my page.tpl.php calls <?php print render($page['content']); ?>? Will modules be the only way? from which I will create my block and add it to the page?

Note: We like to have COMPLETE control over our page. And we are getting rid of views from our site.

  • But this way overrides the whole page.tpl.php, well something is wrong with your site / files, it shouldn't be like this! for instance page--front.tpl.php should only be used for frontpage.
    – user23288
    Sep 23, 2015 at 8:52
  • 1
    You can use Views to display a collection of nodes. You don't need to use any template files.
    – Beebee
    Sep 23, 2015 at 9:14
  • "But I have a page which actually needs to display a collection of nodes." Have you ever heard of views?
    – Huelfe
    Sep 23, 2015 at 9:15
  • With views you don't have a full control. With my custom php, I will do whatever I need. I can change the view based on my wish without digging much,I don't need to change my css to include the components rendered by views. We are getting rid of views from our site. Sep 23, 2015 at 9:18
  • You can write views in code to have more control and even push them to your versioning repositories.
    – leymannx
    Sep 23, 2015 at 9:27

3 Answers 3


You can use the same template, add your custom content to a variable in template_preprocess_page function.

function template_preprocess_page(&$vars, $hook) {
  $path = current_path();
  if ($path == 'url') {
    $vars['custom_content'] = "your custom content";
    $vars['theme_hook_suggestions'][] = 'page__url';

Then print the variable after the content.

<?php print render($page['content']); ?>
<?php print render($custom_content); ?>

Sure your custom page--url.tpl.php overrides page.tpl.php. That's Drupal's template hierarchy. The more precised template will overwrite the broader template. That's why you may simply duplicate page.tpl.php first, rename it, and then start to change it the way you want.

But honestly that really isn't the ideal approach for this. You absolutely should have a look at Views – maybe the most loved Drupal module so far. With this you can create a views page with a fixed URL that will list specified content in a specified way. Additionally you still can do templating with View's templates if you really need it. But you may be happy already with what Views will let you do through its UI.

Also you are not bounded to the UI. Only enable the parent module and write your views in code when you prefer having everything in custom modules.


If you want to customize your node page then you can write tpl file for that node page. If your node ID is 246 (node/246), then you write page--node--246.tpl.php

Otherwise you can display collection of nodes by creating views and render that view in your page.

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.