Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Like Tree4Likes

Thread: Referencing shared HTML content?

  1. #1
    Junior Member LDAsh's Avatar
    Join Date
    Oct 2015
    Posts
    12
    Member #
    52294
    Liked
    1 times

    Referencing shared HTML content?

    Sorry, I'm not a webdesigner at all and I only know basic HTML and CSS. I am sure this is possible but after days of reading through different tutorials, I haven't found exactly what I'm looking for...

    What I have is a website of about 80 HTML pages, and a lot of it is repeating the same chunks of HTML, such as the menu and even small bits like the date. What I'd like to do is, instead of have 80 versions of the same menu, just have 1 "menu.html" and then in each page have something that links that "menu.html" into it, so if I want to make a change, I can just change 1 file instead of 80. The same with the date, it need only be 1 TXT file with a string of text, that each HTML file then references for its content. Ideally, I'd like to do this with as much content as possible.

    At the moment I use a program called ConTEXT to search and replace through these 80 pages to do things like change the date, but it could not only be easier to edit the whole website but use much less KBs also.

    One more thing, I would like it if this is just a HTML trick, hack even, rather than get into the realms of PHP or Javascript. I prefer a trick/hack than getting more technical even if it is considered "proper".

    Any help is deeply appreciated. Thank you.

  2.  

  3. #2
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Hi - First of all, what program are you using to write your HTML pages? Any text editor will allow you to do what I'm about to describe - I use Notepad++ (free download)

    I know you don't want to get into PHP or anything complicated, but really the easiest way to do what you want is with PHP includes. This is one of the simplest statements in PHP - with it you can have the same piece of HTML code appear in all your pages. the pages will all have to be renamed to .php instead of .html for this to work.

    So, if you want the same header to appear in all your pages, you make a file called header.php and copy all your header code into it (you'll then want to remove that code from each of your pages - this is a good time to save the page as .php instead of .html). Where you had your header code before, that's where you put your PHP include, like this:
    Code:
    <html>
    <body>
    
    
    <?php include 'header.php';?>
    
    
    <h1>Welcome to my home page!</h1>
    <p>Some page content.</p>
    <p>Some more page content.</p>
    
    
    <?php include 'footer.php';?>
    
    
    </body>
    </html>
    As you can see in my example, you can do this with the footer as well.
    This lets you change the content of the only header file or the footer file and it will appear that way across all the pages where you have used the PHP include statement.
    There is a pretty good explanation here:PHP 5 include and require
    Vapr_Arts and brandMatt like this.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  4. #3
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    I really cant think of an easier way than what Mare suggested. Php includes is extremely simple to understand and you dont have to do any real php scripting. You just have to know how they work and how html works. I think you will find these very simple to get the hang of even with no other experience using php.

    One thing that you will need to have is a virtual server on your computer. You can download MAMP(for mac) or XAMP,LAMP for other operating systems. This isn't very difficult to get use to either. Once installed you just have to make sure your projects are within a specific folder. Its usually a folder within MAMP. You can even change it. I have mine set to a different folder. Ask if you need any help.


    Sent from my iPhone using Tapatalk

  5. #4
    Senior Member sarahswansea's Avatar
    Join Date
    Oct 2015
    Location
    Swansea, UK
    Posts
    155
    Member #
    52184
    Liked
    65 times
    Simpler even than PHP , you can use Server Side Includes (SSI)

    https://en.wikipedia.org/wiki/Server_Side_Includes

    You just use:

    Code:
    <!--#include virtual="nav.html" -->
    It's a really simple format and is supported by apache and nginx web servers.
    LDAsh and brandMatt like this.

  6. #5
    Junior Member LDAsh's Avatar
    Join Date
    Oct 2015
    Posts
    12
    Member #
    52294
    Liked
    1 times
    Thanks for the replies! This SSI method seems to work nicely, especially because I use a simple TXT file and it fits right into my layers with perfect formatting, but only when I upload the SHTML files to my host. It doesn't work when I view it locally, these places are just empty. I guess I need some kind of server environment setup? I'm using XPproSP3, FYI. I found XAMPP but it's a little heavy and I already have some environments setup on my PCs and I don't like the idea of yet another one on them. Can anyone suggest an extremely lightweight option for this?

    Also, either method is a pain, because I will need to go through every page and rename every "href" to either .PHP or .SHTML, which will break a lot of links, but I guess I'm willing to do that for the sake of things.

    Finally, is there a way to define which part of a single TXT file I can "include", like a start line number and end line number?

  7. #6
    Senior Member sarahswansea's Avatar
    Join Date
    Oct 2015
    Location
    Swansea, UK
    Posts
    155
    Member #
    52184
    Liked
    65 times
    Quote Originally Posted by LDAsh View Post
    so, either method is a pain, because I will need to go through every page and rename every "href" to either .PHP or .SHTML, which will break a lot of links, but I guess I'm willing to do that for the sake of things.
    If you are using apache as the server, you may be able to save a file named .htaccess (note the dot at the beginning) at the base of your website directory with the following line:

    Code:
    AddHandler server-parsed .html
    This will make every html file use SSIs so you don't need to rename them to shtml.

    If you are using nginx or a different server you can do something similar if you can access the server configuration.

    Unfortunately I don't have a good answer for your other two questions sorry!

  8. #7
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    The only other way you are going to get server side programming to work is to have a server. Be it virtual or otherwise.

    If you don't want to use XAMP my next instinct would be uploading it directly to your host via FTP and viewing it live.


    Sent from my iPhone using Tapatalk

  9. #8
    Junior Member LDAsh's Avatar
    Join Date
    Oct 2015
    Posts
    12
    Member #
    52294
    Liked
    1 times
    So far so good with how it's working online, but I'm having a lot of trouble getting the local server to work.

    I downloaded and installed Apache, and had the "service monitor" running but it was obviously not configured correctly because my site was broken when viewed locally, so I followed the instructions found here:-
    How to install Apache on Windows and Configure it to Run SSI & CGIs for more than one Virtual Website
    Now the service won't even start, it says "The requested operation has failed!", even though I triple-checked everything.

    What seemed like a great simple solution at first has quickly become a tech-nightmare. Now it's something to do with CGI scripts? I don't even know what those are...
    _____________________________________

    Okay, I reinstalled it (mainly to get the "httpd.conf" file back to default ) and used a combination of instructions from these 2 sites:-
    http://www.thesitewizard.com/apache/...-windows.shtml
    http://www.georgedillon.com/web/apac...guration.shtml
    Now it seems to be working, but only when I view the site via "localhost". If I view it straight from Explorer in its original location, the site breaks. Is this normal? Is there a way I can make a folder called "websites" and then have multiple sites within that will support Apache/SSI, and I can view them in-tact from their locations instead of needing to use "localhost"?
    Last edited by LDAsh; Oct 21st, 2015 at 08:06 PM.

  10. #9
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    It would be so much more simpler using XAMP. The whole setting up process would have been easier and the folder idea you had is exactly how XAMP works. You have to use localhost no matter what as far as I know. I mean im sure you can go in and do some changes and get it to not need it (maybe?), but doesn't seem worth it.


    Sent from my iPhone using Tapatalk

  11. #10
    Junior Member LDAsh's Avatar
    Join Date
    Oct 2015
    Posts
    12
    Member #
    52294
    Liked
    1 times
    I tried that first, but the installer was giving me errors...


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:28 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com