-1

for example when you link a css document to html without writing the code in the html but linking the css file with html code using 'link' tag

I have a logo and a menu bar which comes in every html page I create and its very long code so I want to create a separate file and then link it with the page. Thanks

Expent
  • 55
  • 1
  • 6

4 Answers4

1

From what I understood, you basically want to create a template to use over and over again. check this out: Best practice to create a template in HTML1

Community
  • 1
  • 1
1

If you want to use PHP code for your question you can use like this.

For example you have header,container and footer area for your website.

use like this it works for you if i understand your question.

your index.php inside :

header.php
container.php
footer.php

your header.php is

<html>
<head>
<link href="style.css">
....
</head>

container.php code inside is

<body>
<div class="MainWrap">..div inside element...</div>

the last page footer.php inside must be have your footer code

<div class="footer">..footer inside div element..</div>
</body>
</html>

you can use footer.php and header.php your all webpage

so your index.php code looks like this

<?php include("header.php");?>
<?php include("container.php");?>
<?php include("footer.php");?>

so for example you have another page contact.php

this page inside code is:

<?php include("header.php");?>
<?php include("contact_.php");?>
<?php include("footer.php");?>
EcoWebtr
  • 79
  • 1
  • 9
1

You can use Server Side includes

<!--#include virtual="/news/news.htm" -->

http://de.selfhtml.org/servercgi/server/ssi.htm

JeromeT
  • 83
  • 6
0

You'll want to be looking at a templating engine. A popular example right now is to use AngularJS. I am not aware of anything in the html5 spec that has that module-based templating built in. Although using jQuery with $('#target').html('<p>inserted stuff<\p>'); would work well too.

  • so if my html file is navbar.html so how would i link it to my home.html file – Expent Jul 06 '14 at 18:06
  • If you're looking to import an already existing html template that's rather complex, you're better off using an example above utilizing PHP or a template defined in an AngularJS directive. –  Jul 06 '14 at 20:10