Article
Dr Design - Closing Popups and Propagating Data
More SSI Magic
Hey Dr. Design,
I have two questions. First, in your last article, you said to use SSIs, you use <!--#include file="menu.txt"-->. Is there a difference between this and <!--#include virtual="menu.txt"-->?
Second, I built a template for a client, and am trying to make updates as easy as possible for myself -- or whoever the Webmaster may be. So I thought I'd use server side includes for the header and footer.
However, the image with the page title is in a table, and is much "higher" than the content. So, I thought I'd use variables in SSI. Here's what I came up with:
<!--#set var="which" value="blah.blah" --
<!--#echo $which-->
However, nothing appears on the screen when I try to run this code. Where am I going wrong? Also, can I do the same thing to output attributes to other tags (i.e. <IMG SRC="[variable here]"> )?
Thanks Doctor! ...and by the way, who REALLY writes the Dr. Design column? Matt? Kevin?
Corbb
Who's side are you on, Corbb? Would you really want me to reveal my true identity and expose myself to the enemy? Also, I count three questions in your email - but that's OK, I'll only charge you for two ;-)
There is a difference between the virtual and file attribute in an SSI include command.
virtual tells the server that the path to the document is a virtual path, and this is commonly used when we want to insert the results of a CGI script. What is a virtual path? Virtual paths are specified by your Web host in the apache configuration file.
Examples of virtual paths are:
DocumentRoot /home/webusers/yourdomain.com/public_html
ScriptAlias /cgi-bin /usr/local/httpd/cgi-bin
So an example of using a virtual path in an include command would be:
<!--#include virtual="cgi-bin/some_script.cgi"-->
file tells the server that the path to the file is expressed as a relative path. So,
<!--#include file="menu.txt"-->
is telling the server the document menu.txt is in the same directory as the current document.
Now, on to your second question. SSI directives are comprised of a command followed by attribute/value pairs.
<!--#command attribute1=value1 attribute2=value2 -->
So the correct code for your example would be
<!--#set var="which" value="blah.blah" -->
<!--#echo var="which" -->
Finally Corbb, you can do as you propose and insert a variable into a HTML tag.
For example:
<!--#set var="myimage" value="imagename.gif" -->
<img src="<!--#echo var="myimage" -->">
For more information refer to the Apache SSI Tutorial and also, the NCSA HTTPd Server Side Include tutorial.