Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Includes in Perl

by Rachy222 (Novice)
on Dec 09, 2007 at 20:04 UTC ( [id://655993]=perlquestion: print w/replies, xml ) Need Help??

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

Hello everyone, I was wondering if someone could help me out, I'm a web deisgner/xhtml builder, professionally I normally design/build a site and then pass it on to a development team for them to make the whole thing work functionally, therefore I have no knowledge of programming languages at all. However I have been asked to put together a site for a friend, as part of this site there is a links area that is included on every page. Obviously I don't want this area to be hard coded on each page due to the obvious updating issues. Therefore I wish to include a separate .htm file containing this links area, into each page. After some research I found out that this is mainly done in .asp, but after looking at my host company I have discovered that they don't support .asp only .perl and .cgi, therefore can anyone give me the complete code to be able to add my include .htm file in my core .htm files? Thanks in advance for your help. Rachael Nelson Update: I don't have SSI on the sever I am working on. Cheers Rachy

Replies are listed 'Best First'.
Re: Includes in Perl
by CountZero (Bishop) on Dec 09, 2007 at 20:28 UTC
    Do you know if the hosting company supports "Server Side Includes" (or "SSI")? If so, that is probably much easier to use than to use Perl to include this "link area".

    You just make one file with the links and "include" it in every page through SSI. To change the links on all pages, you just have to change the links in that one file.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Yeah, according to what I am reading online they support HTML/SSL (shtml)/CGI/Perl. If you have something I can use in SSL that would be amazing too, if you do I'm afraid you will have to write it like an idiots guide cause I'm new to the whole world of programming. Cheers Rachy
        Sorry, "SSL" has nothing to do with "SSI".

        SSL of "Secure Sockets Layer" is a way of making webpages secure by encrypting the communication between server and client.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        "SSL (shtml)"?

        Secure Socket Layer (SSL) and Server Side Includes (SSI) are unrelated.

        SSL is an encryption technology. Secure HTTP (HTTPS) is HTTP over SSL.

        SSI allows the addition of simple dynamic aspects to HTML. Quite often, .shtml files are associated with SSI.

        My fellow monks were talking about SSI.

Re: Includes in Perl
by igelkott (Priest) on Dec 09, 2007 at 20:41 UTC
    Not a direct answer, but when using Apache, I normally use Server Side Includes (SSI) for this sort of thing. The main files are commonly named with a shtml suffix (configurable) and can include tags like
    <!--#include virtual="/common/header.inc-->
    to bring in reusable elements.

    Someone else will certainly post Perl-specific solutions but you might see if this simple approach would be permitted.

    Update: fixed botched link

      I tried that I get the following error an error occurred while processing this directive. As I said I am a total code novice so I could be doing something totally obviously wrong so if you can spot something: Have a folder called includes, in this folder is a .inc file called test which contains one line of text for the time being. I slotted the line you gave me into my .shtml file where I want the text to appear. Then uploaded them all onto my web space. Any ideas? Cheers Rachy
        Ok it appears that I don't have SSI on the server so that would be why the script doesn't work. Thanks for your help though. Cheers Rachy
Re: Includes in Perl
by Zaxo (Archbishop) on Dec 10, 2007 at 02:45 UTC

    I think few Apache installations have SSI completely unavailable; it's probably just not switched on by default. You may be able to switch it on for yourself with an Options line in .htaccess, depending on whether the system apache config permits.

    Failing that, Template Toolkit is great for creating modular text.

    After Compline,
    Zaxo

Re: Includes in Perl
by bradcathey (Prior) on Dec 10, 2007 at 04:21 UTC

    The good monks usually don't like suggestions like this, but I've been in a jam without the tools I need for SSI or proper CGI, so I've resorted to Java-the-script. I create an external .js with an innerHTML on the element id and then place the script tag referencing the external file wherever I need the "include" to appear. Dicey, but it works.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2024-12-05 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (36 votes). Check out past polls.