Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: trying to use #include but I can't get it to work!

  1. #1
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trying to use #include but I can't get it to work!

    I'm trying to use includes to minimise maintenance. I have created the include file as linklist.shtml within a test file aptenia_test.html and uploaded both, but the links just don't appear. From what I've read this should be a simple thing to do. I'm not an html whizz.
    Can anyone help?
    The link is http://www.thesucculentgarden.com.au/aptenia_test.html

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I've moved this to "Other" as includes are server side code, not HTML.

    I'm unfamiliar with the type of include (shtml) you're using. The page you're importing to (aptenia_test.html) probably needs to be given the .shtml extension.

    Try renaming it to aptenia_test.shtml

    Other than that, as long as your server supports it (not all do), and you're using the right syntax, and the file you're trying to import is there, it should be fine.

    See also:

    http://www.htmlbasix.com/includes.shtml
    Last edited by jscheuer1; 12-17-2011 at 05:20 AM. Reason: add - See also . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I think the big question is whether your server supports SSI, and if you have enabled SSI.

    Honestly, SSI is not widely used anymore. (I'm not sure how widely used it ever was.) Even the apache howto page isn't very enthusiastic about recommending it. All other tutorials or use cases I could find date back to 2002-2004 or earlier. Many reference/tutorial pages (at universities, etc.) are unmaintained or simply missing.

    A more modern, fully featured language might be more useful to you (as well as offering a greater support base).

    If you decide to use SSI, you might want to read the Apache howto:

    ..............http://httpd.apache.org/docs/current/howto/ssi.html

    pay particular attention to the "Security Concerns" in the exec section.
    Last edited by traq; 12-17-2011 at 05:26 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Your server probably has PHP available (most do). If not, maybe ASP.
    These languages are a lot more complicated than SSI, because they are more powerful. So I understand wanting to use "simpler and easier" SSI.
    But, in reality, these languages actually are about the same difficulty level for simple operations.

    In other words, you won't have to put in much more effort to use PHP and it will probably be better, certainly more standard. And while you're doing it you'll learn something about PHP which might help later.

    For your information, here's some basic PHP code to include a page. Note that the page must end in the ".php" extension for it to work.
    PHP Code:
    <!--HTML GOES HERE-->
    <?php include('path/to/file.html'); ?>
    <!--HTML GOES HERE-->
    Easy! And there are lots of tutorials out there if you need more help (or you can post here again, of course). By the way, that's how I started using PHP, when I wanted to include some other files in my page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Daniel is right: PHP is to be preferred to SSI using shtml. Shtml-files may 'loose' their include(s) after page-refresh, which is not what we want.
    As a side note: when you still want to use shtml-files, only the includer-files should have that extension. Included files may very well be html-files.
    ===
    Arie Molendijk.

  6. #6
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    The problem may be caused by the fact that you have the contents of the included files between <!-- --> (immediately after <!--#include FILE="linklist.shtml" --> ). Removing those contents may help. And are you sure the included file and the includer are in the same folder? If not, you should use <!--#include virtual="../linklist.html" -->
    ===
    Arie.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by molendijk View Post
    The problem may be caused by the fact that you have the contents of the included files between <!-- --> (immediately after <!--#include FILE="linklist.shtml" --> ). Removing those contents may help. And are you sure the included file and the includer are in the same folder? If not, you should use <!--#include virtual="../linklist.html" -->
    ===
    Arie.
    SSI includes use that comment syntax:

    Code:
    <!--#include virtual = "some.txt" -->
    But, as nearly everyone seems to be saying, PHP includes are better and do not use it.

    I think your main problem is that the 'top' page (the includer) needs to be .shtml, not .html. But the server must support the SSI include, otherwise it makes no difference what code you use.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by jscheuer1 View Post
    SSI includes use that comment syntax:
    Code:
    <!--#include virtual = "some.txt" -->
    John, I know. I was not talking about that line, but about the comment lines BELOW that. The person repeats in comment lines what he has already included.
    ===
    Arie.

  9. #9
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks everyone for your quick replies.
    I've changed the include in aptenia_test.html to read

    <?php include('linklist.php'); ?>

    and the linklist extension.

    Both have been uploaded, but it still doesn't work! Am I supposed to include something in the <head>? Obviously there's something I'm doing wrong.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Rename:

    aptenia_test.html

    to:

    aptenia_test.php
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •