in reply to Re: Perl and SSI
in thread Perl and SSI

Please explain what you mean by putting it in a list and printing it out at the right place. I'm not familiar with this?

The document that the SSI command will process will change, depending on which link is selected. The shtml document is being used as a template and the course description file ($course_desc variable) is the text that describes the course, which will change depending on which course a student selects. So, this information changes, but the basic format of the html document (from the template) does not change. If there is away of importing this information besides using SSI I'm game.

Thanks,

Replies are listed 'Best First'.
Re: Re: Re: Perl and SSI
by glivings (Scribe) on May 02, 2003 at 14:42 UTC
    If you're using Text::Template (and I assume other templating modules will allow you to do the same/similar thing), just replace your the SSI in your template: <!--#include virtual="/crs_desc/%%course_desc%%"/ --> with the code to include the file:

    <% my @contents = (); open (FH, "<", "$course_desc") || die "can't open file: $!"; @contents = <FH>; close FH; $OUT .= @contents; %>
    Then you can fill in the template from your script, and your includes will be there:
    my $q = CGI->new; my $course_desc = "/courses/csci_xxx.txt" if ($q->param('course') eq " +csci xxx"); ... my $tmpl = Text::Template->new(TYPE => "FILE", SOURCE => $template_src +, DELIMITERS => ['<%', '%>'], UNTAINT => 1) || die ("Error loading template $filename: $Text::Template::ERROR +"); my $output = $tmpl->fill_in(HASH => { course_desc => $course_desc}); print "Content-type:text/html\n\n", $output;

    Of course, this can get very complicated, especially since virtual includes are used to include the output of commands, etc. This type of very dirty solution is only suitable for very simple cases - and some might argue (successfully) that it should not be used even then.

    To be honest, I've only used this approach for static files, such as including a header or footer in a template. This approach may or may not be suitable for what you want to accomplish, but if you're doing anything complex, I would suggest using CGI::SSI.