10

I'm new to html and was wondering if there is a way to apply the same content to many html files at once.

For example, if I have many pages, but all those pages have an identical navigation side panel that contains links to all the other pages. Is there any way to change the contents of this side panel without changing it for each individual page? i.e. is there a feature that allows me to make this navigation panel in a separate file, then tell all my pages to include this navigation file?

I know a css file can control the format of many html pages - is there an analogy to this that can control the content of many html pages?

xdl
  • 1,080
  • 2
  • 14
  • 22
  • 1
    This is called a *[Content Management System (CMS)](http://en.wikipedia.org/wiki/Content_management_system)*. You could also use a publishing platform like [WordPress](http://wordpress.org). – Jared Farrish Dec 17 '11 at 23:36
  • 1
    (i)frames? ;) No really don't use it :) – PeeHaa Dec 17 '11 at 23:36
  • 1
    @PeeHaa - You're going to have to be more specific. – Jared Farrish Dec 17 '11 at 23:38
  • @JaredFarrish I don't get what a CMS has to do with 'include' like features. – PeeHaa Dec 17 '11 at 23:38
  • @PeeHaa - It's a method of managing content, of which paged content is one type. The simpler form would be a publishing platform like WordPress. – Jared Farrish Dec 17 '11 at 23:39
  • @JaredFarrish sorry I still don't get what does have to do with includes :P Might be just me though – PeeHaa Dec 17 '11 at 23:41
  • @PeeHaa - http://drupal.org/project/pages A page is a type of content, I don't know how else to explain it. Admittedly, a full-blown CMS is probably not necessary, but it's a common approach. – Jared Farrish Dec 17 '11 at 23:45
  • @JaredFarrish actually a common approach is `server side includes` which a CMS system may implement – PeeHaa Dec 17 '11 at 23:46
  • Check this SO question : http://stackoverflow.com/questions/18712338/make-header-and-footer-files-to-be-included-in-multiple-html-pages – O.Badr Nov 28 '16 at 00:23

4 Answers4

9

You can use PHP to do that. Write the HTML code in PHP file, then add include statement in your HTML. This saves you from having to write same code again and again specially for navigation, etc.

PHP manual explains it.

Hope it helps.

Subash
  • 7,098
  • 7
  • 44
  • 70
  • 2
    Why not link to the actual [PHP manual](http://php.net/manual/en/function.include.php)? – Jared Farrish Dec 17 '11 at 23:42
  • Thank you! I will have a look at that link :) – xdl Dec 18 '11 at 11:19
  • @JaredFarrish I didn't link to php manual as xiaodii said he is new to HTML and the php manual doesn't explain the HTML part of it. – Subash Jan 13 '14 at 06:02
  • As the link in the answer points out, readfile() is better than include when there is no PHP in the file being imported. readfile() just passes the content through to the output buffer. include inserts the content, then parses it as part of the executing script. – Arnold Cross Feb 25 '23 at 01:20
3

You can write the common content in javascript file and include it in your html pages using script tag:

<script src="YOUR_FILE.js"></script>

You can use an online HTML to Javascript converter like this one to generate you javascript code.

O.Badr
  • 2,853
  • 2
  • 27
  • 36
1

Server-side includes or server-side programming languages (like PHP, for example), are often used to do that. All pages just include a shared common file, which contains the common content.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0
<?php
include(file with extension);

?>

You'd have to change your file extension that runs this code to DOT php

Cjueden
  • 1,200
  • 2
  • 13
  • 25