How to adapt a HTML template

Adapting a template is a complementary task to extract a previous HTML page. You want to extract broadly common elements of a page and remove the main content, which makes every page unique.

As a result you will have two different template files, the first of which would be named '_pre.inc' and the second one '_post.inc'. You will need both files in order to EasyDoesIt to be able to correctly render the page.

If you are working on a multi-template site, you may want to name the template files acording to your preferences to get a complete template, apart from the default one: 'micrositeABC_pre.inc' and 'micrositeABC_post.inc'.

For starters, edit a complete HTML page from which you want to extract the template. The code will loosely resemble this:

<html> <head> <title>EasyDoesIt: How to adapt a HTML template</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-language" content="en" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="expires" content="-1" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta name="keywords" content="web development cms framework open source" /> <meta name="description" content="Open source web micro framework intended for development of small web sites" /> <meta name="author" content="Author - www.tarsis.eu" /> <meta name="generator" content="Tarsis.net EasyDoesIt 2.12" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <div id="left_column"> <p>Left column content.</p> </div> <h1>Our company</h1> <p>Here is the main content.</p> [...] <div id="right_column"> <p>Right column content.</p> </div> </body> </html>

Then you remove the content of the page, keeping just the common elements for the template:

<html> <head> <title>EasyDoesIt: How to adapt a HTML template</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-language" content="en" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="expires" content="-1" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta name="keywords" content="web development cms framework open source" /> <meta name="description" content="Open source web micro framework intended for development of small web sites" /> <meta name="author" content="Author - www.tarsis.eu" /> <meta name="generator" content="Tarsis.net EasyDoesIt 2.12" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <div id="left_column"> <p>Left column content.</p> </div> ······· 8< ··· Cut here ························· <div id="right_column"> <p>Right column content.</p> </div> </body> </html>

As you see what we need is to split the rest of the code into two pieces, for the areas before and after the main code.

<html> <head> <title>EasyDoesIt: How to adapt a HTML template</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-language" content="en" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="expires" content="-1" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta name="keywords" content="web development cms framework open source" /> <meta name="description" content="Open source web micro framework intended for development of small web sites" /> <meta name="author" content="Author - www.tarsis.eu" /> <meta name="generator" content="Tarsis.net EasyDoesIt 2.12" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <link rel="shortcut icon" href="favicon.ico" /> </head> <body> <div id="left_column"> <p>Left column content.</p> </div>

...and...

<div id="right_column"> <p>Right column content.</p> </div> </body> </html>

Then you save the two parts in different files as a template: '~/templates/_pre.inc' and '~/templates/_post.inc'.

You will need to use you CSS file, including it at the template folder and refer to it at the 'pre' part of your template as well.

Using EasyDoesIt internal variables

EasyDoesIt provides you with the hability to use common variables which can be used with a PHP 'echo' inside almost every part of the code. Most of this variables begin with an underscore sign (_) just to make it more easy for you to recognize them at first sight. For a complete list of the available internal variables please check the README.txt file.

Some of these variables are configured at the configuration file and others are created on-the-fly with the rendering of every page. Some can be altered at the rendering time, customizing their value for the current page. See 'EasyDoesIt custom tags'.

Many of these variables are useful for customizing the templates and, in particular, the HEAD section of the HTML. You can see here an example of how to modify your code to create a more convinient page header:

<title>EasyDoesIt: <?php echo $_site_title; ?></title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-language" content="en" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="expires" content="-1" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta name="keywords" content="<?php echo $_site_keywords; ?>" /> <meta name="description" content="<?php echo $_site_description; ?>" /> <meta name="author" content="Author - <?php echo $_host; ?>" /> <meta name="generator" content="<?php echo $_software_name; ?> <?php echo $_software_version; ?>" /> <link rel="stylesheet" type="text/css" href="./templates/styles.css" /> <meta name="t" content="<?php echo $_template; ?>" /> <link rel="shortcut icon" href="favicon.ico" />

Making code more maintainable

Since template code can contain elements which may need regular modifcation, you may want to split those elements from pre-template and post-template code, using include files. This elements are usually referred in CMS terminology as blocks or content blocks.

For example, imagine you need to have a news block at the top of the right column of the previous example. You may include a separate block file and keep it at the '~/pages' folder so that while maintaining the site all related files are located at the same folder:

<div id="right_column"> <?php include './pages/_news_block.inc' ?> <p>Right column content.</p> </div> </body> </html>

And the news block ('./pages/_news_block.inc') would look like this:

<h3>News</h3> <p><a href=''>Some piece of news</a></p> <p><a href=''>Another piece of news</a></p>

Notice that since '~/index.php' is the script rendering all pages, all paths for file inclusion should refer to the installation root folder.

Easy Does It

Creating small web sites, in an organized and easy fashion.

How to...

Lazy Badger Team

Lazy Badger

This is our war name regarding open software developing. We have a thing for badgers. You can be up to date about what we are doing by following us on Twitter.