|
|||||
Using HTML Templates with Perl CGI ApplicationsThis demonstrates how Perl CGI applications that display a web page can be developed and maintained more efficiently by using HTML templates rather than hard-coded "print" statements.Our sample application gets the hostname and ip address of the user, then returns a simple greeting which includes the sum of the octets of the user's ip address. Typically this Perl CGI application would be coded like this...
This does the job, but anything more than the simplest web page is difficult to design and maintain with this technique. And turning this over to a web designer who only knows how to use a WYSIWYG editor is impossible. This could be coded more efficiently using a "here document", but you still do not want to give your carefully coded Perl programs to your web designer every time a change to the page design is required. A better solution is to separate the data from the presentation of the data by using an HTML template. All data processing is done within the Perl script, then the results are merged with an HTML template. The template is a standard HTML page that can be easily designed and modified with any text editor or most WYSIWYG editors. Here is what an HTML template for our example would look like...
This template can be easily maintained by a web designer. You can even view it as a regular web page. Substitutable parameters are placed within double angle brackets: <<...>>. Program variables or even expressions can be placed within the angle brackets. Here is our new script...
Using HTML templates separates data processing functions from the presentation of the data. This allows us to easily use complex HTML pages for the presentation of our data. The templates can be edited by a web designer using either a text or WYSIWYG editor, while the back-end processing is managed by the software developer. |
|||||
|
|||||