Monday, October 24, 2005

Designing My Homepage

I want to host my homepage in my NLSU2-Linux box. Today, it's the time to think about it. Since the NLSU2-Linux box is not a powerful machine, it is not appropriate to use Java technology. To put less load on the CPU, it should avoid using too much dynamic pages.

In my past experience, using static HTML, there are many duplication parts among different pages, for example, the page header, page footer, menus.... This make the web-site difficult to maintain. If I need to changes the page header, I need to edit nearly all HTML pages repeatedly. In programming, we avoid code duplication by using functions. How about make web pages? I think template is a solution.

In my homepage, I decided to use PHP as the template language. (To avoid confusion with PHP scripts for dynamic pages, the extension of template files is ".tpl") The following shows a typical page contains header and footer in PHP:

<? include 'header.tpl' ?>

.... the contents here .....

<? include 'footer.tpl' ?>


The "header.tpl" and "footer.tpl" are PHP scripts which generate the header and footer HTML fragments respectively. In PHP, the "include" function embedded the contents of the specific file in current pages, similar to the "include" directive in C/C++. In the homepage, every pages contains header and footer will be like the above example. If we want to change the header, we only need to change the "header.tpl" file once.

However, we need to convert the PHP file to HTML. For example, we have an "index.tpl" file which is a PHP script for generating "index.html". We can issue the following commands:

php index.tpl > index.html

For a complete homepage, there should be many ".tpl" files. I think nobody want to type the above command line again and again. GNU Make is a good utility to do this task.

Since I only have some experience to create a simple "Makefile", it is not enough for handling a complete homepage. I spent some hours to study the GNU Make and hope I can create a generic Makefile tomorrow.

Related links:
PHP
GNU Make

No comments: