Using SSI to Boost Efficiency - Common HTML Blocks
(Page 6 of 7 )
There are blocks of common code I have used on my website. Support for many of my downloadable scripts can be purchased through PayPal. Likewise, these scripts are listed on script sites that have a rating system. The code blocks for both are a little tedious and very similar across all pages.
Part of the problem here is that the blocks are similar, not identical. For IIS users, this means you're out of luck. For Apache users though, the combination of #set and #echo directives are useful. The block for the script rating site is below:
<!-- Script ranking block -->
<form action="http://www.scripts.tld/cgi-bin/rate.cgi" method="POST">
<input type="hidden" name="ID" value="20656">
<table BORDER="0" CELLSPACING="0" bgcolor="#800000"><tr><td>
<table border="0" cellspacing="0" width="100%" bgcolor="#EFEFEF" cellpadding="3"><tr><td align="center">
<font face="arial, verdana" size="2"><b>Rate Our Script</b></font></td>
<td align="center">
<select name="ex_rate" size="1">
<option selected>Select</option>
<option value="5">Excellent!</option>
<option value="4">Very Good</option>
<option value="3">Good</option>
<option value="2">Fair</option>
<option value="1">Poor</option>
</select>
</td>
<td align="center"><input type="submit" value="Go!"></td>
</tr></table>
</td></tr></table>
</form>
<!-- End of Script Ranking Block -->
The only part I'm really worried about here is the value of the ID form field. That is the only part that will change from page to page. Again, I cut the block of code out of my page and drop it into its own file, which I'll call "rateblock.shtml". I replace the value of the ID field with an #echo directive, as demonstrated below in the code excerpt.
<!-- Automated Script Ranking Block -->
<form action="http://www.scripts.tld/cgi-bin/rate.cgi" method="POST">
<input type="hidden" name="ID" value='<!--#echo var="SCRIPT_ID" -->'>
....
Now to put a rating block on one of my pages, I need a pair of directives in my page:
<!--#set var="SCRIPT_ID" value="12345" -->
<!--#include virtual="rateblock.shtml" -->
The block will appear in my pages with the proper value in the ID field. If you get a value of "(none)" in the ID field, you have a mismatch between the variable you set in your page and the value you are echoing in the included file. I lost several minutes trying to resolve that problem.
Next: Business Considerations >>
More HTML Articles
More By Clay Dowling