21286 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2311 Views |
-
RESOLVED: Custom Error Pages

15 September 2009 at 1:19am Last edited: 15 September 2009 10:54pm
I am wanting to create some custom styled error pages. I have had a look through the forums and help topics but just need to clarify the process. For example, if we take the standard 404 error page that is the default which uses Page.ss, how can I get this to use my own template so I can style it separately? I did try creating an ErrorPage.php, ErrorPage.ss but that resulted in a SS warning that there were two ErrorPage.php files ie default in the core and the one I created. I then deleted the ErrorPage.php file that I had created and just left the ErrorPage.ss hoping that SS would treat this in a similar fashion to the templates used when creating a custom login form, however, that did not result in any change.
With the SS CMS admin area for the 'page not found' there is a drop down list for the various error codes, hence I assume that their obviously is probably an easy way to create all your custom error pages if you are wanting to.
Is anyone able to please expand on the method used? Any help would be greatly appreciated.
Thank you
-
Re: RESOLVED: Custom Error Pages

15 September 2009 at 3:52am
With the default install there is a page created of type ErrorPage called 'Page Not Found' that is set to handle all 404 errors. You can edit the content of that as needed. It is structured as a $Layout so it will retain all your styles and just use the content entered to display. This is designed as a 'catch all' for errors and only 1 may exist (as you found out).
If you want to handle other Error types, create a new ErrorPage and set the Error Code to the one you want to setup.
To style the page separately you should be able to create the appropriate ErrorPage.ss to override the default in the theme, just be sure it is in /mysite/templates/ or /themes/your_theme/templates/ErrorPage.ss. Otherwise ErrorPage will always default to the Page.ss style.
-
Re: RESOLVED: Custom Error Pages

15 September 2009 at 1:38pm
Thank you for the information. So, for example, if I wish to override the default 404 error page so that I can style my own and not have it use Page.ss, do I just create a file called ErrorPage.ss in the layouts folder or can this not be done?
For the other error pages, when you say create a new ErrorPage and set the Error Code, are you referring to something like: ErrorPage403.ss? How do I set the error code? Do I create this file as a .php file as well? Does SS automatically detect the type of error according to how it is named and then act with the appropriate error action?
-
Re: RESOLVED: Custom Error Pages

15 September 2009 at 3:07pm
Well scratch above, ErrorPage handling is totally outside the regular path of SS template/DataObject rendering. There is a little hint here: http://doc.silverstripe.org/doku.php?id=error-handling#friendly_website_errors
The Debug class will create a flat HTML page in the assets directory like so:
/assets/error-404.html (regular)
/assets/error-404-en.html (localization turned on, last 2 letters for your language)Dump whatever you want in there as full HTML and you're gold. I'm guessing the reasoning behind this is to reduce rendering load on throwaway error traffic.
-
Re: RESOLVED: Custom Error Pages

15 September 2009 at 8:54pm
Thanks Dale, almost there. I now see that when creating an error page within the CMS, a page is created in the assets folder, using the Page.ss as the template, for each error page that is created.
The only issue I am still having is trying to figure out how I can give these error pages their own individual styling that is dependent from the rest of the site. I did try changing the code in the error-500.html file that was created, to test to see if the format of the published corresponding error page altered at all, but it did not. Tried creating the ErrorPage.ss file again and put it in templates folder then changed the content but did not alter the appearance of the published error page either.
I know it will be something simple as you have described but I can't quite get the idea of how it is meant to work. To me, logically, I would just create an ErrorPage.ss with different styling from the rest of the site and throw this in my templates folder. Hence all error pages would be styled according to that file.
What you stated here seems to make sense but cannot get it to work:
"To style the page separately you should be able to create the appropriate ErrorPage.ss to override the default in the theme, just be sure it is in /mysite/templates/ or /themes/your_theme/templates/ErrorPage.ss. Otherwise ErrorPage will always default to the Page.ss style."
In addition to reducing the rendering load on error traffic, I tend to always style my error pages separately from the rest of the site.
-
Re: RESOLVED: Custom Error Pages

15 September 2009 at 10:54pm
Ok, got it sorted. It was as you suggested in your first post:
"To style the page separately you should be able to create the appropriate ErrorPage.ss to override the default in the theme, just be sure it is in /mysite/templates/ or /themes/your_theme/templates/ErrorPage.ss. Otherwise ErrorPage will always default to the Page.ss style."
I had neglected to flush the db hence the changes were not showing.
Thank you for your help!
| 2311 Views | ||
|
Page:
1
|
Go to Top |


