Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Multiple Web Pages With Same Structure

I have a website consisting of more than 40 static (no CMS) HTML pages where they all have the same exact header, navigation, footer and sidebar areas; the only part that changes for each page is the main content area. My question is: is there a way in HTML5 to structure each page such that it pulls in the header, navigation, footer and sidebar sections from a separate file, and then include the content for the page (as detailed below)? Being a programmer by training, it would seem to make it easier to make global modifications with this structure, but I am unable to find out how to make this work.

<head> … </head>
<body>
  (insert header.html)
  (insert navigation.html)
  (insert sidebar.html)
  body content of page…
  (insert footer.html)
</body>

Is this a valid approach to take, and if so how can I make it work? Or would the extra files create unnecessary delays in the page loading into the browser? Right now, if I want to make any changes to the structure or layout of the site, I have to modify all 40-plus pages - not an efficient way of working in my mind.

2 Answers

Elliott Frazier
PLUS
Elliott Frazier
Courses Plus Student 9,647 Points

Totally a job for PHP. with PHP you can do exactly what you described plus more! and whats even better is training for PHP is offered right here on Treehouse - Build a Simple PHP Application. I've completed the course and loved it!

hope this helps :)

Kevin Korte
Kevin Korte
28,148 Points

Exactly the answer. Easy peasy with PHP

Agreed.

Ryan Cocuzzo
Ryan Cocuzzo
1,206 Points

How do i insert a header file into a question?

Ok, with this consensus, I am taking this course on PHP as we speak. Thanks for pointing me in the right direction!