|
Flow ControlOnce I'd got a standard navbar onto each page, I thought it'd be nice to give my visitors a visual cue as to which page they are on. The obvious way to do this was to disable the link for the current page. Thankfully, SSI provides an easy and effective way to do this thanks to its conditional expressions. As any programmer will tell you (I hope), conditional expressions are used when you want one of two or more things to happen. In SSIs, this is done with 4 tags. These are:
These tags are often used in conjunction with variables to alter the page contents depending on certain conditions. In my case, I set a variable to the current page name and do various things depending on it. I think this calls for a snippet from my code.
On line 1, I get the current document name and store it in a variable ($page) so that I can refer to it in the 'if' statements. Note - that's not a typo. When defining variables you omit the '$', but you need it when you use them. On line 2, I check $page to see if this page's name contains the string 'index'. The slashes (/.../) signify I'm using a regular expression; when used like this, the expression will return true whenever 'index' appears anywhere in the page name. Line 3 is the normal HTML I want to display if this page is the index, i.e. a pushed in button and the word 'Home' with no hyperlink, like this:
Line 4 is the 'else' tag. This tells the parser that I've finished with the code I want to return if the expression was true, and am about to start on the code for when the expression is false. Lines 5 and 6 are the HTML code for when the expression is false and this is not the index, i.e. a raised button and a hyperlink pointing to index.shtml, like this:
Finally, Line 7 tells the parser that I've finished with this particular 'if' segment. Any HTML after the <!--#endif --> will be printed regardless. This technique is then repeated for each of the sections I want to display in the navbar.
|