- 1 Tips and Tricks for Detecting Insider Threats
- 2 Red Hat Enterprise Linux 7.5 Debuts with Improved Server Admin Features
- 3 Opportunity Lost: Enterprises Could Slash Cloud Costs by 36 Percent
- 4 Intel Sheds Wind River Embedded Division
- 5 Linux 4.16 Released with Improved Security, Virtualization Features
E-Commerce Solutions: Template-Driven Pages Page 3
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:
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; @opts = qw/paa imac beos/; = [rand(@opts)]; open(FILE,'/usr/local/http/webs/mcwords/ssi/' . . 'buypanel.html'); while(<FILE>) { print; } close(FILE);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.