Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    Call HTML into another page?

    Hello. I was wondering if there was a way I could make a webpage import html from another file into a page. E.g.

    index.html:
    Code:
    <import html="1.html">
    <import html="2.html">
    <import html="3.html">
    ect...
    1.html:
    Code:
    <div class="main-content">
    blahblahblah
    <img src="url">
    blahblah
    </div>
    This will make it ALOT easier to maintain and update. And will make the code on the main page much easier to see, because I want to add a lot of images. I know that forums use php to call in different style sheets. Something like @import.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    If you have a php or some other serverside support, it's very easy.
    PHP Code:
    <?php
    include "1.html";
    ?>
    But the above code should be in a page having a .php extension, otherwise you'd need to add some htaccess rules to for your server to treat your html files like your php files
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    martynball (04-03-2009)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Do you know what htaccess rules I need to add. And where do I put that php code? Because I want it to add the other files in certain places. Well, In a table.

    So would I add

    Code:
    <?php
    include "1.html";
    include "2.html";
    include "3.html";
    ?> 
    ect...
    Between the <td></td> tags?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Between the <td></td> tags?
    Yes, if it's in a php file,
    PHP Code:
    <td><?php include "1.html";?></td>
    ...............
    <td><?php include "2.html";?></td>
    should work.

    PS: Do you know why tables for layout is stupid?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    martynball (04-03-2009)

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    I have seen that website to many times Lol. I know tables are bad, but I am a very basic coder Lol. I cant be bothered learn stuff like that yet.

    Could I just save my page as a php file like it is? Or would I have to change stuff about?

  • #6
    New Coder
    Join Date
    Apr 2009
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    if you change your page extension as .shtml yo can include another file into your page
    use that code to include a file:

    <!--#include file="addedfile.html" -->

    for more info about shtml click here..

  • Users who have thanked SurFeR for this post:

    martynball (04-03-2009)

  • #7
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    You only need to work with the htaccess file if you are changing the way the HTML documents are served. If you're using plain PHP (as in "page.php" instead of "page.html") you won't have to bother with the htaccess file at all.

    Before you look too heavily into PHP though, have you made sure that PHP is available on your hosting server? If not, you might have to resort to javascript.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    martynball (04-03-2009)

  • #8
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    I will probably be using x10 hosting, they have php. It is all working now as well. Thanks people.


  •  

    Posting Permissions

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