Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Perl executing SSI/ include virtual

by Avitar (Acolyte)
on Jul 30, 2004 at 22:32 UTC ( [id://378823]=perlquestion: print w/replies, xml ) Need Help??

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

Anyone know how to execute a SSI / shtml directive in a Perl / CGI app? I saw a few posts regauding this, but no one was able to solve it. There is a really good reason for doing it: If you have a template file that contains a SSI tag that you read in, you would need to parse that tag too. This way you can make several modular scripts instead of lots of big CGI programs. A rough example: index.shtml:
<HTML lang=en> <HEAD><TITLE>Nested shtml Menu Test</TITLE></HEAD><BODY> <!--#include virtual="/cgi-bin/hello.cgi"--> </BODY></HTML>
hello.cgi:
open(DATA,"hello.template"); @template=<DATA>; close(DATA); print "Content-type: text/html\n\n" for($a=0;$a<=$#template;$a++){ print $template[$a]; }
hello.template:
<!--#include virtual="/cgi-bin/nest.cgi"-->
nest.cgi:
print "Content-type: text/html\n\n" print "<BR><B>Nesty Nest";
part of the problem I have faced is that custom directives in apache are not obeyed by CGI::SSI so i would like to rule out that module unless someone has some advice on a workaround. ------------- update: I found CGI::SSI_Parse which does almost everything I need. I am gutting the module to work the way i need. Ty for all the help!

Replies are listed 'Best First'.
Re: Perl executing SSI/ include virtual
by epoptai (Curate) on Jul 31, 2004 at 04:05 UTC
    Check out CGI::SSI

    --
    perl -MO=Deparse -e"u j t S n a t o e h r , e p l r a h k c r e"

      This was my first instinct, however it does not maintain apache directive info very well from my understanding. Then again i don't think it is possible to have it both ways =(

      I think i will have to make a custom module that will read custom apache directive info and then tie it in with the CGI::SSI module somehow.

      Also I belive CGI::SSI is broken since it does not appear that you can pass the ssi output to a variable... instead the intent is to force it into a file. please correct me if im wrong.
Re: Perl executing SSI/ include virtual
by beable (Friar) on Jul 31, 2004 at 03:08 UTC

    You could try looking at the template for SSI tags, and if there is one, use do or eval to execute it. Here's an example:

    open(DATA,"hello.template"); my @template=<DATA>; close(DATA); print "Content-type: text/html\n\n"; for my $line (@template) { # you should probably use an HTML parsing module # here instead of a regex if ($line =~ m/<!--#include virtual="(.*?)"-->/) { my $include = $1; do $include; } else { print $line; } }
      ya this is something like i was thinking of =) TY for your help!
Re: Perl executing SSI/ include virtual
by ggg (Scribe) on Aug 02, 2004 at 00:03 UTC
    This solution may be going in the wrong direction for you, but perhaps you can adapt something here.

    I think I remember that the server will parse anything ending with ".shtml". If you rename your hello.cgi to hello.shtml, it will be handled by the server also. In this way you can nest SSI include commands. I don't think I ever tried this with more that one level of nesting, but it may go deeper.

    ggg
      But there is more to it than nested shtml files... For instance if i want to add a web based mailer/contact form. There would be a page that would be layed out like the following pseudo-Code: Contact.cgi contains ( Header.template contains ( header text, news.cgi output, menu.cgi output) print contact form here Footer.template contains ( footer text, footer_menu.cgi contact_info.cgi ) )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://378823]
Approved by PERLscienceman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-23 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found