Developing Component-Based Pages with HTML::Mason
By Lincoln D. Stein
In recognition of this month's Open Source theme, the topic of this column is Open Source component systems for the Web, with emphasis on the full-featured HTML::Mason system for Apache.
What are Web components? Components are anything that can be mixed and matched to build larger Web pages. They can be static snippets of HTML, dynamic server-side programs such as CGI scripts, or dynamic client-side software such as JavaBeans.
Components actually have a long and distinguished history on the Web. The first component-based systems were server-side includes, introduced with the NCSA httpd server. With server-side includes, you can build full pages from bits and pieces of HTML boilerplate using specially formatted HTML comments. Before sending the document to the browser, the server scans for such comments and takes actions ranging from pasting in the contents of a file to inserting the contents of system variables.
For example, the bit of code shown in
Example 1 inserts a standard disclaimer into the Web page by pasting in the contents of the file standard_disclaimer.html. Provided that every page on the site inserts the disclaimer using this server-side include statement, the disclaimer can be modified by changing just the single file, saving you from having to do a wholesale edit of every HTML file on the site.<>