Gerard has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, I have been asked to redesign the naviagtion for a site, that currently has not real flow, or consistency to the navigation.

Having made my own version of the increasingly popular dhtml drop down menu system, I have been asked to include it on every page using a SSI, something along the lines of
<html> <head title="Existing page on site, so can I keep all my existing tags + please> <!-- #include virtual = "/header.inc" --> </head> <body> <!-- #include virtual = "/nav.inc" --> Existing html </body> </html>
This works like a charm, but the problem comes when trying to apply this same simplicity to perl generated html pages. At first I was surprised that when including the above code within an html here doc, it did not work.

A few seconds later, after actually thinking about it I realised that it made sense for it probably not to work.
What I really want to know is if there is an easy work around, or what the best / simplest way to do this might be.
Fortunately there are only four or five scripts to edit.

Any comments / suggestions much appreciated.
Regards,

Gerard

Replies are listed 'Best First'.
Re: SSI Not being processed
by Wysardry (Pilgrim) on Jan 24, 2003 at 00:59 UTC

    "So you want to include SSI directives in the output from your CGI script, but can't figure out how to do it? The short answer is "you can't." This is potentially a security liability and, more importantly, it can not be cleanly implemented under the current server API. The best workaround is for your script itself to do what the SSIs would be doing. After all, it's generating the rest of the content."

    -- Apache FAQ

    In other words, you have two choices:-

    1. Build static HTML pages (with the SSI calls in) instead
    2. Pull the content into your existing script and print it along with your other HTML

    __________
    "Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, one can deduce that every program can be reduced to one instruction which doesn't work." -- (Author Unknown)

      I feared as much. The problem being that, (thankfully) I am leaving this position shortly, but am unlikely to be replaced with someone that knows anything about perl, and there is no one else in this small company that does know any perl now.

      I would much rather leave things as simple as possible for the not so technically minded. i.e. editing the file to be included shouldn't be too much of a problem for them, but editing the perl script would be.

      I think that I would be best off to open the files to be included in the script read in the entire contents and print it back out in the same place as they would be if they were using the ssi.
      Just wanted to check that there was no other SSI way to do this.

      Thanks, Gerard.

        Well, neither of the solutions I gave need be that complex.

        To do the first, your existing script would only need to be modified to print to a file instead of the screen/browser.

        The second solution, again using your existing script, wouldn't require the script to be edited more than once. It would just read from the include files and print them - they wouldn't need to be physically inside the code. The technically challenged would just edit the included file, and leave the Perl alone.

        I risk being hung, drawn and quartered for even suggesting this, but is using PHP an option? (That has SSI type functions built in).

        __________
        "Every program has at least one bug and can be shortened by at least one instruction -- from which, by induction, one can deduce that every program can be reduced to one instruction which doesn't work." -- (Author Unknown)

Re: SSI Not being processed
by Ovid (Cardinal) on Jan 24, 2003 at 01:10 UTC

    SSIs are great if you have duplicated content on an essentially static site. However, you're trying to create dynamic content, so you may as well go all the way and adopt a template system like HTML::Template or Template Toolkit. Both of those solutions are good (and there are other good ones) and will give you greater flexibility in the long run.

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

      Thanks for the suggestion, and it is a good one.

      Unfortunately, I do not think that I would have time to redevelop all 500 odd pages of the site before I leave the position in less than a week and a half.
      Also, the amount of dynamic content, compared to static content, is quite small, as the majority of the site is made up with legal information etc. that only changes when the government passes a new tax law or something like that.

      I do not think that this size is set up in the most 'maintainer' friendly manner, but my suggestions and comments have not always been respected or taken notice of, hence the leaving.

      Thanks for the comments
      Gerard.
Re: SSI Not being processed
by perrin (Chancellor) on Jan 24, 2003 at 03:42 UTC
    Don't worry, you can easilly process SSI directives in CGI output with one of these CPAN modules.