mainajaved
mainajaved

Reputation: 8173

How to make same layout for all web pages

I am currently working on HTML I want to ask a question about website development.I am developing a website in which the basic layout remains same like menu, side menu etc but only the content changes.Currently I have make separate .html file for all web pages. Can any one tell me is there a way through which I can make a separate file having etc common to all and call it in my html file.I have heard about CSS but it will only change the style and layout. thanks

Upvotes: 10

Views: 47439

Answers (5)

Manse
Manse

Reputation: 38147

If your HTTP (apache 2 and IIS do) server supports Server Side Includes then you can just include another HTML file :

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

your content

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

no need for a server side language then - just plain HTML

Upvotes: 14

Luca Reghellin
Luca Reghellin

Reputation: 8103

Yes, your best bet is a server side language, as Adam said. Absolutely avoid using the old style html frames: they're deprecated, and cause a certain number of problems, both on the programming side and on google optimization.

By using a server side language, you'll still have entire pages, but they will be partially generated by php (or asp) by printing more files into one. For example:

http://www.php.net/manual/en/function.include.php

Bye!

Upvotes: 1

Starx
Starx

Reputation: 78981

This is very big topic to include in just one answer. SO I will give only the logical part.

Separate your template into multiple chunks like:

1. header.php
2. leftSidebar.php
4. rightsidebar.php
5. footer.php

Now, include these common part on your every page.

For example: index.php

<?php

    include "header.php";
    include "leftSidebar.php";
    echo "<div>".$thedifferentpart."</div>"; //Change only this part on every other page you will create.
    include "footer.php";

?>

NOTE: This is only a logical part, applying the concept on your code

Upvotes: 4

PenguinCoder
PenguinCoder

Reputation: 4357

I don't believe that is possible, strictly through HTML. However, you could use server side scripting like PHP to get it done. What you're talking about is a template, and is used quite often. What you would want, is to have your menu items (and CSS) and your header/footer code in separate pages. This way, if you make changes to the menu, or header/footer, it would be reflected in all the pages (written with PHP) you have scripted with the template method.

You would need the menu.html, header.html and footer.html in a place accessible by your main page code. That is, you would use the template method to write the content of your pages.

A psuedo code example in PHP would be like such:

<?php
   include('header.html');
   include('menu.html');

    echo "Your main content items here";

   include('footer.html');
?>

Upvotes: 0

KingCronus
KingCronus

Reputation: 4519

Your best bet in the long term is to use a server side language like ASP.net or PHP

Upvotes: 0

Related Questions