0

I'm trying to override the default page template for a specific page I created. I created a new page and then created a new template file called page--node--1.tpl.php and added the following code:

<?php
echo 'test?';
exit;
?>

I'm using 'garland' as a theme and it's still showing garland's template.

1
  • Did you copy the default page.tpl.php to you r theme as well, and then clear the caches?
    – Clive
    Commented Jan 31, 2013 at 16:08

1 Answer 1

1

Adding a template file to an enabled theme is like adding a hook to an enabled module: In both the cases, Drupal will not notice there is a new template file, or a new hook, as Drupal keeps that information cached.
After you add a new template file, you need to clear the Drupal cache, or disable the theme for then re-enable it. In the latter case, you forces Drupal to clear the relevant caches.

As side note, exit should be never used in a template file, not even for debugging. Doing so, you would interrupt Drupal when it calls theme_render_template(), with the effect that the template file would not be rendered.

function theme_render_template($template_file, $variables) {
  extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
  ob_start(); // Start output buffering
  include DRUPAL_ROOT . '/' . $template_file; // Include the template file
  // The code after this comment is never executed, if the template file executes exit().
  return ob_get_clean(); // End buffering and return its contents
}

For debugging purposes, it's enough to print a specific string that allows you to know if the template file is loaded.

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.