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

I need to include a file along the lines of: <!--#include virtual="/directory/structure/file.pl?project=projectName-->

But I have a problem. I don't know in advance what project I need to include. I want that to be passed to the file in the main URL like:
www.site.com/directory/file.shtml?project=projectNatme

I have parsed the variable into a usable Javascript variable, and tried to write the include file into the page like
 document.write( '<!--' + '#include virtual="/directory/structure/'+'file.pl?project='+projectName+'"-->'); in an attempt to pass the information onward to the Perl script, but this is not working. (If I don't split up the include call, the include happens without the variable being added. If I do, it doesn't work at all.)

I suspect that there is a better way to get the information to my file.pl, but I don't know what that might be. Here is the caveat: file.pl can't be run as a standalone CGI. It HAS to be an include. Any ideas?

Replies are listed 'Best First'.
Re: Telling a file included in a web page something
by clwolfe (Scribe) on Jun 28, 2006 at 03:23 UTC
    Hi lishevita,

    Well, this is really off-topic - this isn't a perl question so much as an apache question.

    The first thing you need to clear up is some misconceptions about what executes where. Your <!-- #include --> is a server-side include (SSI) - in other words, it executes on the server. Your proposed fix - which is certainly the right kind of thinking - won't work because Javascript executes on the client side, in the browser, long after the response has left the server (and thus the SSI handler).

    You can learn a lot more about SSI from http://httpd.apache.org/docs/2.2/howto/ssi.html. It sounds like you don't have control over the webserver, and you don't have privileges to execute anything on the webserver. In other words, if you can't execute file.pl as a CGI on its own, you certainly won't be able to include its output via SSI. So, you just won't be able to do anything dynamic on the server end.

    And thus you may be barking up the right tree with the Javscript. Just drop the SSI. Why not have the main page load, read the requested project from its own URL, somehow(*) fetch the contents of the project using Javascript, and then write the contents using document.write statements.

    (*) Therein lies the rub. Here's a few ways.
    1. Use IFRAME tags. Only supported by IE.
    2. Make your page a frameset, and make one frame have zero width; then load your auxilary content in the spare frame. Some browsers won't allow a zero-width frame.
    3. Like the frameset approach, but use window.open to make popup windows and load the content there. Of course, pop-up blockers will snare you.
    There is no perfect solution this way; each involves ome trade-offs. Anyway, my $0.02 . Good luck.