I know this is a beginner’s question, but I’ve been searching online and all I can find are “free website templates” that I can download.
The question is:
How can I write a segment of HTML in a single file, and then load that exact same segment into any other HTML files that I choose?
The intent is so that if that segment changes, I would only have to change 1 file, rather than 10’s/100’s/1000’s/etc.
For example, I might want to define a menu bar like this:
<a href="./Test1">Test1</a> <br />
<a href="./Test2">Test2</a> <br />
<a href="./Test3">Test3</a> <br />
And then, so I don’t have to keep repeating that same code in every single file, I could just link to this menu bar. Maybe something like:
<html>
<!-- Load "Menu Bar" file -->
<!-- Place the menu bar right here -->
Thanks for visiting my web page. Please navigate with the menu bar above.
</html>
Thanks.
Edit: Though it might sound trivial, I wanted to make a few HTML pages to manage some of my personal files and data. As programmers, we of course do not like to repeat ourselves. My initial thought was that this was as simple as linking to a CSS file, but I see now it is more complicated, though I’m not sure (from a technical standpoint) why it has to be. In any case, since I’ll be viewing the files on my own machine, I suppose I can install something like PHP to aid my efforts.
You are describing server side includes.
Example of usage:
This will add the text of
quote.txtto the page – if you add it to multiple pages, you can make your change in this one file and it will show on all pages in was included in.Different web servers have different support and additional features for these, so you need to check the documentation for yours.
Many websites that need dynamic features (like fetching data from a database) will use some kind of server side scripting language for this kind of functionality – examples include PHP, Perl, ASP.NET, JSP and many more.