The #set Command

The #set command allows you to add your own variables that can be used with the #echo command. For format of a #set command is:

<!--#set var="..." value="..." -->

For example:

<!--#set var="title" value="My document's title" -->

The #set command is extremely powerful as it provides a means of passing 'arguments' to recursively included SSI pages. This is because the #set command adds to the global variable environment, so a parsed document can set a variable then include another parsed document which uses this variable, or vice versa. For example:

File title.shtml:

<!-- requires title -->
<!-- Imagine this is a complicated table -->
<!-- which puts the title at the top of -->
<!-- the page in a standard fashion. -->
<html>
<head>
<title><!--#echo var="title"--></title>
</head>
<body bgcolor=#ffffff>
<table bgcolor=#f0f0c3 cellspacing=4>
<tr>
<td>
<font size=+3>
<!--#echo var="title"-->
</font>
</td>
</tr>
</table>

Then we could use this complex standard title in a document "About Zeus" as follows:

<!-- Set title, and include standard document header -->
<!--#set var="title" value="About Zeus" -->
<!--#include file="title.shtml" -->

Document body goes here.

<!-- We'd probably do the footer in the -->
<!-- same way, but for now we'll just -->
<!-- terminate the html manually. -->
</body>
</html>

Using the #set command allows the reuse of 'components' of HTML and is extremely useful in large web-site design.

Content Manager [Administrator] 16 December 2005 Bookmark with del.icio.us Post this article to Digg Post this article to reddit Post this article to Facebook Tweet this article  

Comments are closed for this post.

Recently...

Other Resources