0

I looked around, but couldn't find a satisfying answer.

Problem: I have a menu bar that appears on the top of the page. I want it to show across all of the pages on the website. So how would someone do that without copying the same code each time. Would someone use html, php, css, or javascript/jQuery to accomplish this?

Note: I want to have a separate html file to access the information from.

2 Answers2

1

From what I have seen, this is typically done with php using a template file.

The template file may have HTML code in it that you want to display on every page, as well as placeholders for content that is page specific. e.g: template.php

<html>
  <head>
    <title><?php print $title; ?></title>
  </head>
  <body>
    <nav>Test</nav>
    <?php print $content; ?>
  </body>
</html>

In this case, as long as $title and $content variables are set, you can then do a include 'template.php'; to output this HTML code in other php files.

Read more about php's include.

Aiias
  • 4,683
  • 1
  • 18
  • 34
  • I'm not quite sure how I would do this for a seperate document –  Jun 09 '13 at 00:10
  • @ReubenRenquist - First you need to setup a `php` development environment. I would look for online tutorials on how to do this, or get a free hosting account that supports `apache`/`php`. – Aiias Jun 09 '13 at 04:17
0

It seems that you will need to use include, although an explaination on how to use it (or at least an example can be found here: https://www.youtube.com/watch?v=XmoF-6vshSI