HTML - Includes Without Using Php Or Shtml
I have a script for a navigation bar that I want to include on all my HTML pages using some kind of include tag so that I don't have to paste the script into each page every time I edit it.
The only way I can get it to work is if I use either PHP or SSI include tags but this requires me to change all my page extensions from .html to .php or .shtm. So I can get it to work, but the thing is, I don't want to have to change all my extensions. I like my pages in .html and it would be a pain change them all. Is there a way to do what I am trying to do without having to change all my extensions? Some kind of HTML equivalent for include tags? Or some code that forces my HTML documents to read PHP or SSI tags? There's got to be something right? Similar TutorialsI'm converting my webpages from a .html file to a .shtml file because I'm using SSI in the page. Now, can I just change the file type or do I have to do other stuff to the file? Thanks Hi, geetings to all. I came across this interesting feature on the Microsoft website and I was wondering how the navigation bars work? (the one with highlights etc...) I suspect it's done using javascript... Can anyone link/provide me to/with any code, tutorial or explanation as to how this is done? Thanks. =) As for shtml, I remember doing it once but I forgot how it's done. My question is, does shtml operate on frames? Is there a good tutorial out there somewhere? (I'm sure there is, I'll be searching meanwhile too). Thanks for your help. DarkArcher I'm currently helping someone maintain a pretty simple website, mainly text. And they would like to update their site relatively often, but I don't have the time and they don't have the knowledge of updating the page. So I was wondering if I could just embed the text into the html file using a .shtml file (ex <!--#include file="maintext.shtml" -->) and create a form on a seperate, password protected page that would have a simple textarea and submit button that would allow them to edit the text in the .shtml file and press submit, therefore editing the text in the .shtml file? Is this possible? If I have many PHP includes, will this slow down the loading of the page? I may have around 6 at a time on a single page. <? $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/item.php"; include_once($path); ?> I usually have around 6 of these on a page at a time, will this slow down the loading of my website. I use this for updating my website, since all the includes come from the same sources, e.g. navbar on all pages comes from /include/navbar.php then I will have to edit navbar.php to edit the navbar on all pages. Am I using the correct method for website updating, or is there a more efficient way? So I bought a template a while back that has a lot of includes files, which don't really work for me. Whenever the includes file tries to link to another page in the website it points to a /includes first so instead of linking to index.htm it links to includes/index.htm Obviously this links to a page that doesn't exist which leads to a junky website with a ton of broken links. I've already tried "recalculte hyperlinks" and it didn't help at all. Does anybody have any idea or ever experienced this before? Thanks for any help that you guys can give. =D Hi all, brand new here. A little history. I am an employee of a very small company that had a website built for them. I was given the task of updating it on a regular basis (it is for a group of movie theatres, so it is updated constantly). Well it was build 4 years ago now and the person who built it used frames. We are wanting to bring it a little up to date so I'm redesigning one at the moment that was be much more simplified. What I'm trying to accomplish is this: I want to be able to have a page that has Form - List/Menu that has the days that each theatre has movies scheduled for. Then, when that date is selected, the showtimes part of the page changes to show that dates showtimes but the rest of the page stays the same. After doing some research I THINK what I need to be using is Server Side Includes...but I'm having trouble figuring out how to get this to work. If you want an example of what I'm after you can go to any major movie theatre chain's website (like movietickets.com) and they have what I'm trying to accomplish. ANY help would be appreciated. Thanks! I've acquired a series of websites that, unfortunately, were all created using Dreamweaver and as such all use purely html files. I need to include a "widget" of sorts across all the websites. It is written in php, hence I'm looking for a way to simply include this php file in the sidebar of all of the websites, which are written in html. This also means I'll be including the file from a different domain using the full URL I gave SSI a shot, but no luck. hey everyone. i'm taking a course in website design this semester and we've gotten to SSI which I am a bit confused over. we're supposed to have built a page with header, menu, footer and then we will be using those three on another 4 pages. so he wants us to pull the header, menu, footer code out and use it with SSI. my question is, what do i need to pull out of this code to make a SSI file that i can then bring in on various pages so they look the same on each? the site is at: http://thing.cs.usm.maine.edu/~mckenney/demo/index.html Okay, so I have a small issue here. I started a webcomic, and I'm now redesigning the website. I'm using SSI includes on my pages, and I'm having an issue with my navigation. I want to be able to include first comic/previous comic/next comic/current comic buttons, but the problem is this: with the previous comic/next comic buttons, I'm not really sure how to code it. I can't type in the name of the page I want it to go to, because then it'll be the same on every page. Is there a way around this? I figured I could tell it to go "next" and have it refer to "next" somewhere on the individual pages, which would send it to the next comic in the sequence, but I can't find the coding to do that, and I can't figure out the right way to word it to find it in a search. If I'm not too vague, can you guys help me out here? Thanks! Introduction: Seeing as this question is brought up very often, I hope this short guide will be a destination for users seeking information about the topic. Although this is a server-side issue, those who are not aware of this fact generally seek help in HTML/XHTML, so this is where the topic will remain Note: Read the answers to Frequently Asked Questions in the next post! Hasn't this been done before? Absolutely; this is meant as a straightforward stickied version that brings a few things together and references previous threads where you can find further details. If your question is somewhere in the realm of one of these, you're in the right place: How do large websites manage their content? How do I make the same content appear in multiple pages without copy/pasting? How do I automatically update parts of different pages, without editing every file? How do I avoid duplicating code in multiple files? Is there an alternative to IFrames? The answer is using PHP Includes, SSI (Server Side Includes), or ASP Includes. Each will be discussed below. Basic Concept: Let's assume we have a basic HTML page with a few links that represent a navigation menu (we're using HTML5 markup for simplicity): Code: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Main Page</title> </head> <body> <div> <ul> <li><a href="home.html">Home Page</a></li> <li><a href="gallery.html">Gallery Page</a></li> <li><a href="about.html">About Page</a></li> <li><a href="contact.html">Contact Page</a></li> </ul> </div> </body> </html> This HTML page is now our basic template for subsequent pages that we create, which traditionally meant that we copy and paste our menu into each one. However, what if we end up creating 50 pages and then find out we have to add another link to the menu? Our only solution would be to add the link to each page. In order to avoid this, we separate our menu from the rest of the page like so: Code: <div> <ul> <li><a href="home.html">Home Page</a></li> <li><a href="gallery.html">Gallery Page</a></li> <li><a href="about.html">About Page</a></li> <li><a href="contact.html">Contact Page</a></li> </ul> </div> Save it in a file, and then place an include on every page where we want to display the menu: Code: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Main Page</title> </head> <body> code for including menu would go here </body> </html> This setup lets us update our menu file, and have the changes be immediately reflected everywhere we placed our include. The concept is most often used with things like menus, headers, and footers, but it can be used with anything and we'll now discuss how it's done in practice. Note: The attached zip contains working examples of all three methods. PHP Includes: General Requirements: Your web-hosting provider must support PHP, which most of them do. If your host does not support PHP, I would suggest switching hosts. If you do not have a hosting provider, and you're attempting this on your local computer, it must be set up as a local server and configured to run PHP. The easiest way to do this at once is by installing XAMPP. Required Filetypes: By default, servers will only parse PHP code inside files with the .php extension. Therefore, you must change the extension of any files you want to use includes in to .php (e.g. index.html becomes index.php). Although your main file must have a .php extension, you can include files with extensions such as .html, .txt, .inc, other .php files, and more. Syntax Here are two ways to include a file in PHP: PHP Code: <?php include('file_to_include.html');?> or: PHP Code: <?php include 'file_to_include.html';?> Note that you can also include full URLs if URL file-access is enabled in your server's configuration: PHP Code: <?php include("http://www.google.com/");?> Code Example: (some_page.php) Code: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>PHP Include</title> </head> <body> <?php include("menu.html");?> </body> </html> Server Side Includes (SSI): General Requirements: Your web-hosting provider must support Server Side Includes, which most of them do. If you do not have a hosting provider, and you're attempting this on your local computer, it must be set up as a local server and configured to support Server Side Includes. If you are using Apache, you can find information on enabling SSI here. If you are using IIS, you can install Server Side Includes inside Windows Features > World Wide Web Services > Application Development Features > Server Side Includes, although this path may differ depending on your version of Windows. Required Filetypes: By default, servers will only parse Server Side Includes inside files with the .shtml, .shtm or .stm extensions. Therefore, you must change any files you want to use includes in to have one of these extensions (e.g. index.html becomes index.shtml). Although your main file must have one of the above extensions, you can include files with extensions such as .ssi, .html, .txt, .inc, and more. Syntax Here are two ways to include a file using SSI: Code: <!--#include file="menu.ssi" --> Is used to specify a relative path, i.e. a path to your include in relation to where your main file is. The above assumes that your main file, and menu.ssi are in the same directory. Code: <!--#include virtual="includes/menu.ssi" --> Is used to specify a path relative to the web root. The above assumes that menu.ssi is located inside webroot/includes Code Example: (some_page.shtml) Code: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>SSI Include</title> </head> <body> <!--#include file="menu.ssi" --> </body> </html> ASP Includes: General Requirements: Your web-hosting provider must support ASP. If you do not have a hosting provider, and you're attempting this on your local computer, it must be set up as a local server and configured to support ASP. If you are using Apache, you can find information on enabling ASP here. If you are using IIS, you can install ASP inside Windows Features > World Wide Web Services > Application Development Features > ASP, although this path may differ depending on your version of Windows. Required Filetypes: By default, servers will only parse ASP code inside files with the .asp extension. Therefore, you must change the extension of any files you want to use includes in to .asp (e.g. index.html becomes index.asp). Although your main file must have a .asp extension, you can include files with extensions such as, .html, .txt, .inc, other .asp files, and more. Syntax Here are two ways to include a file using ASP (The syntax is exactly the same as SSI): Code: <!--#include file="menu.html" --> Is used to specify a relative path, i.e. a path to your include in relation to where your main file is. The above assumes that your main file, and menu.html are in the same directory. Code: <!--#include virtual="includes/menu.html" --> Is used to specify a path relative to the web root. The above assumes that menu.html is located inside web root directory/includes Code Example: (some_page.asp) Code: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>ASP Include</title> </head> <body> <!--#include file="menu.html" --> </body> </html> Hi all, I have a query that I hope somebody can help with as my site has been brought to a standstill because of this problem. I have just posted the new version of my site online and I have a folder below the domain root which contains things like database info, form scripts etc. When I process the form I get a 404 error. the action is something like HTML Code: action="../includes/process_form.php" There is no need to any output from these files as they process the information and direct to the relevant files above the domain root using php header scripts. At the beginning of most of my files I have the following PHP Code: <?php $security = 'secure'; require('../includes/default.php'); require('../includes/error_handlers.php'); require('../includes/db.php'); ?> and there is no problem with these whatsoever. I had all of the scripts working fine when I tested them at domainroot.co.uk/take2/public/ domainroot.co.uk/take2/includes/ Does anybody have any ideas why this is happening Any help would be appreciated John |