Miscellaneous of OpenCart: Broken glass 404 error page

A 404 error indicates that the client was able to communicate with the server, but the server could not find what was requested. In this recipe, we will create a customized 404 error page: a page that appears when a user types a non-existing page of a website. We will place some images along with navigational links on the error page.

1. Getting ready

We open the not_found.tpl file under the Catalog\view\theme\shop\template\ error.

2. How to do it…

Let’s list the steps required to complete the task:

  1. First, we will create the HTML structure of the We’ll replace the existing code of the not_found.tpl file with the following code:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http:// www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” dir=”ltr” lang=”en” xml:lang=”en”>

<head>

<title>Your Store</title>

<meta name=”description” content=”My Store” />

<link rel=”stylesheet” href=”catalog/view/theme/shop/stylesheet/ master.css” />

</head>

<body>

//…

</body>

</html>

  1. In the css stylesheet, we first reset the browser styles with the following code:

@charset “utf-8”;

/* Default Values */ a {

outline: none;

}

div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,te xtarea,p,blockquote,th,td {

margin:0;

}

table {

border-collapse:collapse;

border-spacing:0;

}

fieldset,img {

border:0;

}

address,caption,cite,code,dfn,em,strong,th,var {

font-style:normal;

}

ol,ul {

list-style:none;

}

caption,th {

text-align:left;

}

h1,h2,h3,h4,h5,h6 {

font-size:100%;

font-weight:normal;

}

q:before,q:after {

content:”;

}

abbr,acronym {

border:0;

}

object {

outline:none;

}

q {

display:block;

}

q:before, q:after {

content:””;

}

  1. We have set the reset styles; now, we will apply general styling:

/* General layout values */

html {

height:100%;

}

body {

height:100%;

background-color:#010e16;

margin: 0;

padding: 0;

font-family: Arial, Helvetica, sans-serif;

color:white;

}

  1. In the body section, we place the following content:

<div class=”subheader”>

<div class=”gratz”>

<p class=”lead”><strong>Grats.</strong> You broke it.</p>

<p>This page doesn’t exist or some other horrible error has occurred.</p>

</div>

</div>

  1. In the browser, we can see our 404 page as this:

  1. To change the font style, we are using the following font property:

p.lead {

font:22px/1.964 ‘Century Gothic’, ‘Lucida Sans Unicode’, ‘Lucida Grande’, ‘Lucida Sans’, Verdana, Arial, Helvetica, sans-serif;

}

  1. This brings the following changes:

  1. Let’s apply some colour to the texts:

p.lead {

font:22px/1.964 ‘Century Gothic’, ‘Lucida Sans Unicode’, ‘Lucida Grande’, ‘Lucida Sans’, Verdana, Arial, Helvetica, sans-serif;

letter-spacing:-1px;

color:#77cff1;

}

  1. Let’s look at the browser:

  1. Then, apply some margin to it:

p.lead {

font:22px/1.964 ‘Century Gothic’, ‘Lucida Sans Unicode’, ‘Lucida Grande’, ‘Lucida Sans’, Verdana, Arial, Helvetica, sans-serif;

letter-spacing:-1px;

margin:20px 0 1.964em;

display:block; color:#77cff1;

}

  1. We will go to the browser to find the following changes:

  1. To the strong HTML tag, we apply this style:

p.lead span {

display:block;

padding:.982em 0 0;

}

p.lead strong {

font-size:28px;

line-height:1.179;

}

p.lead sup {

font-size:.5em;

}

  1. Then, the texts appear as the following:

  1. In the gratz class, we are going to use the following styling for the positioning:

.gratz {

position:absolute;

top:440px;

right:180px;

text-align:right;

z-index:116;

}

  1. So, we find the position as this:

  1. Again, for the styling of the fonts, we apply the following style on the gratz class:

.gratz p.lead {

font-size:36px;

margin:0 0 5px;

}

.gratz p.lead strong {

font-size:36px;

}

.gratz p {

font:12px Arial, Helvetica, sans-serif;

color:#82B8CB;

margin:0;

}

  1. And, in the browser, we find this:

  1. We now add some HTML wrapper to the gratz There is some inline css styling, you can place them in the master.css also:

<div class=”subheader”>

<div class=”temp” style=”display:block”>

<div class=”brokennavcontainer”>

<div class=”brokennavloc” style=”background-image:url(catalog/view/theme/shop/image/ brokennav.gif);”>

<div class=”brokennav”>

>Grats.</strong> You broke it.</p>

<div class=”gratz”>

<p class=”lead”><strong

<p>This page

doesn’t exist or some other horrible error has occurred.</p>

</div>

</div>

</div>

</div>

</div>

</div>

  1. Here is the gif:

  1. Now, we need to use some styling properties on these classes:

.brokennavcontainer {

background:url(../image/gratz.jpg) 50% 0 no-repeat;

height:575px;

z-index:110;

margin:0 auto;

position:relative;

text-align:center;

}

  1. Here is the gratz image:

  1. We have to use the following extra styles for the above mentioned classes:

.brokennavcontainer {

width:954px;

height:572px;

left:0;

position:absolute;

top:0;

left:0;

z-index:117;

}

.brokennavloc {

background-position:50% 0;

background-repeat:no-repeat;

}

.brokennav {

width:954px;

height:552px;

top:0;

z-index:111;

margin:0 auto;

position:relative;

}

  1. These styles bring the following changes to our 404 page:

  1. We add two more classes on the So, the code block becomes the following:

<div class=”subheader”>

<div class=”temp” style=”display:block”>

<div class=”brokennavcontainer”>

<div class=”brokennavloc” style=”background-image:url(catalog/view/theme/shop/image/ brokennav.gif);”>

<div class=”shatter2″></div>

<div class=”brokennav”>

>Grats.</strong> You broke it.</p>

<div class=”gratz”>

<p class=”lead”><strong

<p>This page

doesn’t exist or some other horrible error has occurred.</p>

</div>

</div>

</div>

</div>

</div>

</div>

<div class=”shatter1″></div>

  1. For the shatter1 and shatter2 classes, we will use some images in the Find some broken glass images on the Internet. We will use two broken glass images. First, for the shatter1 class, we use the following style:

.shatter1 {

width:674px;

height:549px;

left:-40px;

z-index:110;

top:0px;

background-image:url(../image/shatter1.png);

position:absolute;

}

  1. We find the status of our page as this:

  1. Then for the shatter2 class, we also have another image:

.shatter2 {

width:262px;

height:285px;

right:0px;

z-index:109;

top:348px;

background-image:url(../image/shatter2.gif);

position:absolute;

}

  1. With the two images, the page appears like the following:

  1. Now, we will add footer after the subheader div on the First, we will see the HTML structure of the page:

<div class=”footercontainer”>

<div class=”footer”>

<div class=”footercontents”>

<div class=”footercontents_int”>

<div class=”links”>

<span class=”spacer”>|</span>

<a href=”#”>Press</a>

<span class=”spacer”>|</span>

<a href=”#”>Career Opportunities</a>

<span class=”spacer”>|</span>

<a href=”#”>Privacy Policy</a>

<span class=”spacer”>|</span>

<a href=”#”>Contact Us</a>

<span class=”spacer”>|</span>

<a href=”#”>Sitemap</a>

</div>

<br /><br />

<p class=”dark”>

All trademarks referenced herein are the properties of their respective owners. <br />&copy;2010 Shops commerce system. All rights reserved.

</p>

</div>

</div>

</div>

</div>

  1. With the footer, our 404 page becomes the following:

  1. We positioned our footer with the following code block:

.footercontainer {

background-repeat: no-repeat;

background-position: top center;

background-color: #010E16;

width: 100%;

height: 90px;

padding: 80px 0 0 0;

}

  1. This moves the footer to the following position:

  1. Now, we will beautify the footer with the following styles:

.footer {

clear: both;

margin: 0 auto;

width: 980px;

}

.footer .footercontents {

width: 100%;

clear: none;

height: 60px;

}

.footer .footercontents .footercontents_int {

color: #FFF;

font-size: 11px;

text-align: center;

}

  1. The above styles make our footer look like this:

  1. For the footer navigation, we use the same styling to separate its contents:

.footer .footercontents .spacer {

color: #012839;

font-size: 13px;

padding: 0 5px 0 5px;

}

  1. The footer navigation changes as the following image shows:

  1. To complete our footer styling modification, we add some colour to the copyright texts:

.footer .footercontents .links {

font-family: “Lucida Sans Unicode”, “Lucida Grande”, sans-serif;

line-height: 14px;

display:inline;

}

.footer .footercontents .dark {

color: #bbb;

font-family: “Lucida Sans Unicode”, “Lucida Grande”, sans-serif;

line-height: 14px; margin: 0;

}

  1. Then, this section appears as the following when we refresh our browser:

3.  How it works…

We have used some background images for the 404 page. We then used z-index for those images. We added styling properties to our page to make it look eye catching.

There are many different designs for the 404 page. Also, you can use your imagination to make your own 404 page.

4.  See also

⯈ Sitemap creation.

Source: Hasan Tahsin (2011), OpenCart 1.4 Template Design Cookbook, Packt Publishing.

Leave a Reply

Your email address will not be published. Required fields are marked *