Simplified Site Management: The Power of SSI (Part 3 of 3)

Posted on Wed 30 March 2022 in Programming

Welcome back to the final installment of our exploration into Simplified Site Management using Server Side Includes (SSI). If you haven't followed the previous episodes, I encourage you to catch up to fully grasp the concepts we're about to dive into. In our previous discussions, I promised to provide you with a visual representation in the form of a crude flowchart, and I'm here to deliver on that promise. Be sure to click on it to get the full view, and feel free to keep it open in another window as a reference.

 

As you've been following along, you might be wondering where all of this is leading. What's the grand vision behind splitting our web pages into various files and using SSI to orchestrate them seamlessly? Well, let's delve into that now.

 

The core idea here is to enable the editing of specific sections of a website within individual files while safeguarding against unintentional and site-wide changes. It's all about maintaining well-formed markup across the board. Well-formed markup is the bedrock of a stable and functional website. It ensures that every tag opened is properly closed, except for singular instance tags like "img," which do not require a closing counterpart.

 

Imagine you're responsible for maintaining a website with a consistent left-hand navigation menu across its many pages. Now, with traditional methods, altering this menu could be a daunting task, requiring updates across numerous files. This complexity increases the likelihood of errors and site-wide disruptions.

 

However, by employing the strategy we've been discussing, you can make changes to that menu in a single file, such as "left_menu.html," knowing that your modifications will exclusively affect that specific part of the website. It's like precision surgery for your site updates—no accidental changes to the header or content sections.

 

Let's take a closer look at the "index" file, which I refer to as the requested file—the file that your web browser requests when you visit a webpage. This index file governs the customized sections of your webpage. Here's where the magic happens. Let's say you've promised a vendor a prominent skyscraper ad in the right-most column of most pages, but some pages have only three columns, sans the skyscraper. On all other pages, you want four columns: the usual three plus a fourth with that eye-catching animated skyscraper ad.

 

In the default values file, you'll notice the use of the "!" symbol, which signifies "not" just like in many programming languages. So, "! $title" evaluates to true if no "title" value has been set. This technique allows us to provide sensible default values for variables, ensuring that we never have undefined states or unhandled variables.

 

Moreover, I've introduced a "sanity check" for the "$right_column" variable in the default values file. This ensures that "$right_column" will always be either "yes" or "no," avoiding any ambiguous states in between.

 

In practical application, you can condense these conditionals into single lines, reducing clutter and maintaining clarity. While Apache leaves a blank line for each line used, which might lead to excessive white space at the top of the file, it doesn't impact functionality.

 

Now, when it comes to the skyscraper ad conditional, I placed it in the page loading file to ensure that the div for the ad is only present on pages that explicitly include it.

 

In practice, I typically use fewer lines in each file, and the conditionals are more concise, all on one line. The key takeaway is that this approach to site management streamlines updates, minimizes the risk of errors, and enhances efficiency.

 

You can explore SSI directives in greater detail in the Apache Docs, tailoring your SSI strategy to match your server's specific version. If you encounter any version-related challenges, don't hesitate to reach out, and I'll be more than happy to assist.

 

And with that, we conclude this series on Simplified Site Management using SSI. If you have any questions or need further guidance, please feel free to ask. Happy programming, and may your websites always run smoothly.

 

Footnote:

Later, I implemented a web page that allowed office staff to access these files without requiring FTP access, reducing the risk of unintended deletions.