Your Daily Source for Apache News and Information |
Breaking News | Preferences | Contribute | Triggers | Link Us | Search | About |
\n'); } if ( plugin ) { document.write(' '); } else if (!(navigator.appName && navigator.appName.indexOf("Netscape")>=0 && navigator.appVersion.indexOf("2.")>=0)){ document.write(''); } //-->
|
This is the third in a three-article series about Server Side Includes, or SSI. In the first article, I discussed configuring your Apache server to permit SSI. In the second article, I gave some examples of how you might use SSI to add dynamic content to your web pages. In this article, I'll talk about some of the advanced features available with Server Side Includes. (Note: Most of the features discussed in this article are only available to you if you are running Apache 1.2 or later. Of course, if you are not running Apache 1.2 or later, you need to upgrade immediately, if not sooner. Go on. Do it now. We'll wait.) Setting VariablesUsing the <!--#set var="name" value="Rich" --> In addition to merely setting values literally like that, you can use any other variable, including, for example, environment variables, or some of the variables we discussed in the last article (like <!--#set var="modified" value="$LAST_MODIFIED" --> To put a literal dollar sign into the value of your variable, you need to escape the dollar sign with a backslash: <!--#set var="cost" value="\$100" --> Finally, if you want to put a variable in the midst of a longer string, and there's a chance that the name of the variable will run up against some other characters, and thus be confused with those characters, you can place the name of the variable in braces, to remove this confusion. (It's hard to come up with a really good example of this, but hopefully you'll get the point.) To wit: <!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" --> Conditional ExpressionsNow that we have variables and are able to set and compare their values, we can use them to express conditionals. This lets SSI be a tiny programming languages of sorts. The structure of this conditional construct is: <!--#if expr="test_condition" --> <!--#elif expr="test_condition" --> <!--#else --> <!--#endif --> A In your configuration file, you could put the following line: BrowserMatchNoCase macintosh Mac BrowserMatchNoCase MSIE InternetExplorer This will set environment variables Mac and InternetExplorer to true, if the client is running Internet Explorer on a Macintosh. Then, in your SSI-enabled document, you might do the following: <!--#if expr="${Mac} && ${InternetExplorer} --> Apologetic text goes here <!--#else --> Cool JavaScript code goes here <!--#endif --> Not that I have anything against IE on Macs--I just struggled for a few hours last week trying to get some JavaScript working on IE on a Mac, when it was working everywhere else. The above was the interim workaround. Any other variable (either ones that you define, or normal enviroment variables) can be used in conditional statements. With Apache's ability to set environment variables with the ConclusionSSI is certainly not a replacement for CGI, or other technologies used for generating dynamic web pages. But it is certainly a great way to add small amounts of dynamic content to pages, without doing a lot of extra work. See the docs on |
|
|
About Triggers | Media Kit | Security | Triggers | Login |
All times are recorded in UTC. Linux is a trademark of Linus Torvalds. Powered by Linux 2.4, Apache 1.3, and PHP 4 Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy. |