E-Commerce Solutions: Template-Driven Pages Page 3

Although this kind of layout is not particularly unique or clever, it does make the whole process a lot easier. It also ensures that I can easily identify the elements that I want to include. This will become particularly important as we start to embed different elements through our script engines.

Quasi-Dynamic Content

Up to now, we've strictly been dealing with static pages. Although it's possible that some of your content will be static based, it's highly unlikely that your entire site will be able to make direct use of SHTML pages. We'll be looking at how to build entirely script-driven sites that employ templates in the next article. Until then, we can actually introduce some further dynamic content without resorting to a full script.

Using the exec SSI directive we can execute a CGI script instead of embedding a static HTML file. Most sites actually use this feature to include a site counter, but it can be used in any situation where you want some dynamic content. On my site I've used this as a way of introducing some random elements into the various side panels that would otherwise have to be manually selected on each page.

The script is pretty simple; it only has to select a file from a predefined list and then open and send it back. Because the script is still parsed by the server though it does need to output an appropriate header. You can see the script below:

print "Content-type: text/html\n\n";

@opts = qw/paa imac beos/;

 = [rand(@opts)];

          .  . 'buypanel.html');

This is not a suitable solution however for anything more complex than embedding a flat script, we can't supply arguments, and the request isn't made in the same way as calling a CGI from the client. Still, we're beginning to get the basis of a dynamic template-driven environment.

The Next Step

The basics applied in this article will work with any template-driven system. In every system, from SSI to a Perl, Python or other script driven solution the aim of templates is to centralize the HTML. That makes developing and updating the site easier--you only have to change one file--and it also provides consistency across the entire site.

In the next article we'll move on and see how we can use different scripting engines and the same basic template principles. We'll also look at parsed templates, as opposed to the static templates we've seen in this article.

Martin C. Brown is a full-time writer and consultant specializing in multiplatform integration and internet technologies. He is author of both the Perl and Python Annotated Archives and Perl The Complete Reference.

This article was originally published on Jun 28, 2000
Page 3 of 3

Thanks for your registration, follow us on our social networks to keep up-to-date