-1

So I'm working on producing my own version of a web/db project my friend was given in school. This is my first project in either area and I'm still learning. Part of the project description mentions all of the pages the client wants. I'm solving this by making an unordered list of links to the different pages with appropriate labels. Complex, I know.

Then I realized that every page will have this. My question is this: is there a way to class certain portions of code in html, so I can just have a "navigation list" in each page, instead of the full code of the list and everything associated with it, in every page?

I want the code to be clean and efficient. That's my motivation in this question.

  • 1
    Please provide your code of what you have tried. Also, by the sound of it, this seems like a question more fit for http://codereview.stackexchange.com/ – Dom May 29 '15 at 21:41
  • @Dom, he doesn't have a file of code he wants to improve, he just wants a better way to put the same menu in every html file without copy/pasting each time the list of links changes. – user1717828 May 29 '15 at 21:44

3 Answers3

0

What you are talking about is templates. You cannot do it in plain html... You would need to use a server side language like php. You could also do it with a JavaScript templating language like handlebars or similar, but not in plain html.

Sean Stopnik
  • 1,868
  • 11
  • 9
  • You can also use offline templating through some programs. Like Grunt and Jekyll – OdraEncoded May 29 '15 at 21:47
  • Okay great. I was thinking of something along those lines. So an example would be to create an object in php and use it in all of the pages? – Andres Rosales May 29 '15 at 21:48
  • No... You would just make a file for each template. For example, you can have '_nav.php'. Then in your index.php file you would include the nav template '' – Sean Stopnik May 29 '15 at 21:58
  • @OdraEncoded Yep, exactly right. I use codekit quite a bit for basic sites, and that has a simple templating feature built in as well. A lot of options out there. – Sean Stopnik May 29 '15 at 22:02
0

Your question provides little detail, but it sounds like you want something like a php include. If you are running your site on your local, change the .html files to .php and do <?php include('includes/navigation.php') ?> where includes/navigation.php is a path to JUST your navigation code.

Shan Robertson
  • 2,742
  • 3
  • 25
  • 43
0

If you don't want to use PHP or some other server side technology for a simple menu, you can try various Javascript plugins like MenuCool.

user1717828
  • 7,122
  • 8
  • 34
  • 59