...

Conditional includes (SSI)

AndyB
12-15-2002, 05:18 PM
What I need to do would be a trivial exercise if I could use php. Unfortunately php is not available on the server where this problem needs to be solved (and neither is ASP available).

I need to include a variable in an shtml page and use that variable to determine which other includes are written. This is in the context of a menu system, where if the page is about 'widgets' then additional menu links relating to widgets need to be written into the menu, and similarly if the page is about 'elephants' then different additional menu links need to be written.

If it's possible, a simple and complete code sample would be extremely helpful.

Otherwise, I guess I'm stuck with doing the same basic thing client-side using javascript with doc.writes for menu parts - and I'd prefer to avoid that as this particular client believes many surfers run with javascript disabled.

MCookie
12-15-2002, 07:58 PM
<!--#set var="page" value="$DOCUMENT_NAME" -->
<!--#if expr="$page = /widgets/" -->
<!--#include virtual="/includes/more_about_widgets.html" -->
<!--#elif expr="$page = /elephants/" -->
<!--#include virtual="/includes/more_about_elephants.html" -->
<!--#elif expr="$page = /coffee/" -->
<!--#include virtual="/includes/more_about_coffee.html" -->
<!--#else -->
<!--#endif -->

Which reads like this: if the name of the page contains 'widgets', the file more_about_widgets.html will be included; if the page name contains 'elephants', more_about_elephants.html will be included, and so on.
If the pagename contains none of the expressions <!--#else --> nothing will be included.

AndyB
12-15-2002, 10:26 PM
Excellent. That works flawlessly - on my server (which I know is a *nix server).

On my client's server (probably a pacbell service) it fails as the directives fails. Checking with BigNoseBird's tutorial (http://www.bignosebird.com/sdocs/extend.shtml), the explanation given is "If you are using Netscape Server or IIS, you will need to check their documentation for the solutions.

As I don't happen to have IIS (or Netscape server) documentation around .... is there a solution that a mere mortal would understand?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum