Is it possible to make CustomError use a custom page template, ala page-customerror.tpl.php?

Comments

physiotek’s picture

would be very nice :)
was coming here in the issues section with he hope of finding such an info...

pht3k

kbahey’s picture

I have not tired, but it should work in principle.

In the template.php file of your theme, add the following function:

function phptemplate_customerror($error_code = 404, $content = NULL) {
return _phptemplate_callback('customerror', array('error_code' => $error_code, 'content' => $content));
}

Then create a customerror.tpl.php and put in it what you want.

Not sure if it will do what you want, but worth a try.

physiotek’s picture

hi,

well i was asking because i wanted back the columns drupal 5.1 removed from the error pages, and i just found here how to do this:
http://drupal.org/node/129762

but thanks for your reply; it is some info i was seeking for an other issue...
pht3k

mairav’s picture

What @kbahey mentioned in #2 in Drupal 6 would be:

function phptemplate_customerror($error_code = 404, $content = NULL) {
	return theme_render_template('sites/all/themes/afd/customerror.tpl.php', array('error_code' => $error_code, 'content' => $content));
}
krystianbuczak’s picture

Hi,
I have just tried your function but doesn't work. What's wrong, any idea?

K.B.

mairav’s picture

In

function phptemplate_customerror($error_code = 404, $content = NULL) {
return theme_render_template('sites/all/themes/afd/customerror.tpl.php', array('error_code' => $error_code, 'content' => $content));
}

You have to change the word "afd", for the name of your theme, and then place in your theme folder the file customerror.tpl.php with the template in the way you want you custom error to appear.

kbahey’s picture

Better than hard coding the theme path, you can do:

function phptemplate_customerror($error_code = 404, $content = NULL) {
return theme_render_template(base_path() . path_to_theme() . '/customerror.tpl.php', array('error_code' => $error_code, 'content' => $content));
}

The code will be more portable this way.

mairav’s picture

@kbahey Thanks! that did the job!

krystianbuczak’s picture

Even I create empty customerror.tpl.php file or leave only print $content line in the file all default page areas (header, content, footer) are still loaded.
So, I guess that this code doesn't help me to change the way 404 page will be displayed. Am I right?

Thanks for all answers.

madwalo’s picture

i have almost the same problem but i have seen the same with other functions i try to use, phptemplate_ or themename_ functions never wors, i am using clean theme
many thanks

garethsprice’s picture

Issue tags: +empty, +page not found, +custom 404

No need to use CustomError to do this (although it'd be nice if it had support for it).

Set your error page to "404" under the "Error Reporting" textboxes.

In your template.php:

function phptemplate_preprocess_page(&$vars) {
  if(arg(0) == '404'){
    $vars['template_file'] = 'page-404';
  }
}

Source: http://drupal.org/node/603748

adr_p’s picture

Or, if you have CustomError enabled:

function phptemplate_preprocess_page(&$vars) {
  if(arg(0) == 'customerror'){
    $vars['template_file'] = 'page-404';
  }
}
gisle’s picture

Status: Active » Fixed

Looks like this support request has received an answer.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

alexkb’s picture

In Drupal 7, you can override the template, simply by creating a "page--customerror.tpl.php" template. No preprocess calls are required in your template.php. If you want to have a different template for the 403 and 404 pages, simply create "page--customerror--403.tpl.php", "page--customerror--404.tpl.php".