Home     SSI Lab     CSS Templates     CSS     Htaccess     Web Design     XHTML

X-SSI Lab

graphic-img   



Basics of Conditional SSI

Bookmark with StumbleUpon
del.icio.us
Digg it
reddit
Furl
Spurl
ma.gnolia
Yahoo MyWeb
Windows Live
Sponsors

Introduction

This guide introduces the very basics of conditional SSI with some simple examples.


Conditional SSI "Flow Control" allows you to test for certain variables and display content depending on what those variables are. To better explain it consider the following scenario:

If your browser is Netscape:
   "Netscape Rules!"
or else if your browser is Internet Explorer:
   "IE Rocks!"
otherwise:
   "display no message"
End

The correct syntax takes this basic format:

<!--#if expr="expression" -->
   "something here"
<!--#elif expr="expression" -->
   "something else here"
<!--#else -->
   "something different here"
<!--#endif -->

To show this in a working example we are going to display a simple message depending on what day of the week it is.

First we configure the time format for the full weekday name, then we check what day of the week it is and attach the appropriate message:

<!--#config timefmt="%A" -->
<!--#if expr="$DATE_LOCAL = /Monday/" -->
<p>I hate mondays!</p>
<!--#elif expr="$DATE_LOCAL = /Friday/" -->
<p>Yeeah, it's Friday!</p>
<!--#else -->
<p>No comment!</p>
<!--#endif -->

Conditional SSI is where it gets exciting as it allows you to add a great deal of dynamism and personalisation to your pages and so is important to learn and experiment with. More examples & applications are accessible through the main SSI page.

It's also important to check out the conditional expressions page to learn what 'operators' can be used with conditional SSI.