Forum Moderators: coopster & phranque

Message Too Old, No Replies

ssi includes in cgi script output

         

martyk

3:18 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



Hello all. I have a question. Let's see if I can explain it correctly.

I am using a plain old html template to build a website. I am using ssi includes for things like the menu and ads. These work fine for most things but when I return an output for a cgi script the ssi doesn't work. The templates for the cgi output have been wrapped in my own templates with the ssi includes. When I go to the input screen of the scripts the menu shows up but when the script returns it's output it is gone.

How can I get my cgi scripts to parse the ssi in it's template? I have tried fooling with the .htaccess file but can't seem to figure it out. Any help would be appreciated.

Marty

Philosopher

3:23 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's not likely going to work...at least not easily.

CGI output is not processed for additional CGI commands such as includes. It's treated as regular text/html.

martyk

3:49 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



Ok, I figured it would be a problem. It seems when you think something will be easy it never is. Any suggestions on how I can get the cgi scripts to pull the menu files (they are plain text files) without having to hardcode them into the templates? BTW the script itself doesn't have the includes in them. An html template is pulled by the script and then output with the results.

perl_diver

7:00 pm on Oct 26, 2006 (gmt 0)

10+ Year Member



CGI::SSI is not really a solution I like but sometimes it's necessary or at least easier than rewriting templates or scripts to get SSI stuff working using open() or other perl method:

[search.cpan.org...]

rocknbil

8:33 pm on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure if I totally get the question, but it's actually pretty easy to include SSI's in your script output.

For static HTML of course you do this:

<!--#include virtual="/path/to/script.cgi?p=value1:value2" -->

Something to note which will become apparent in a minute: the format with which I query a script from a static include is an ordinary query string, but it only has one key/value. The value is colon separated. This is to make it compatibile with @ARGV, perl's default argument vector.

To include the SSI script's output in a script within a template, I do an equivalent except as an argument vector. An ARG isn't key/value, it's a list. This is where the colon above comes in, it takes the split values as an argument vector:

$arg = "value1 value2";
$include = `perl script.cgi $arg`;

For your template, use a "marker" and substitute it instead of an include line:
(read in the template)
if ($line =~ /\<COLUMN1\>/) { $line =~ s/\<COLUMN1\>/$include/; }

You have to modify script.cgi a little bit so it can read/parse as well as accept vectors, like so. @ARGV is the default perl argument vector variable:

if (@ARGV) { ($value1,$value2)=@ARGV; }
elsif ($ENV{'QUERY_STRING'}) { %qs = &your_read_parse; ($value1,$value2)=split(/:/,$qs{'p'}); }
else { &error("No type specified"); }

The last part of the equation - you need to print a content-type for a normal SSI. If you do that for a script include, the program calling it will error or exit (hmm can't remember which it does. :-) )

if (($ENV{'QUERY_STRING'}) && ($qs{'p'})) {
print "content-type: text/html\n\n";
print "$out";
}
else { print "$out"; }

I hope this is close to what you're asking. :-)

martyk

2:57 am on Oct 27, 2006 (gmt 0)

10+ Year Member



Thanks for the replies everyone. I think perl_diver might have the solution I need but I have to figure it out. I'm not really too familiar with perl programming so my head is spinning a little trying to learn it all today. I'll give perl_diver and rocknbils' suggesions a try if I can figure out what they mean :)

perl_diver

6:01 am on Oct 27, 2006 (gmt 0)

10+ Year Member



for my suggestion to work you will most likely have to install the CGI::SSI module or ask tech support to install it for you.