Download & Extend

make CustomError use a custom page.tpl.php?

Project:CustomError
Version:5.x-1.1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:custom 404, empty, page not found

Issue Summary

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

Comments

#1

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

pht3k

#2

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.

#3

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

#4

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));
}

#5

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

K.B.

#6

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.

#7

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

<?php
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.

#8

@kbahey Thanks! that did the job!

#9

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.

#10

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

#11

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

#12

Or, if you have CustomError enabled:

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