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

Kelly Walsh
Kelly Walsh
3,642 Points

Building a simple website with reusable content / making a template?

I am building a pretty simple website so far with just html and css. The site has 10 pages, and the navigation bar, footer, etc. are the same.

Without using a tool like Dreamweaver (I have it for work but prefer to use Notepad ++), is there a simple way to make resuable content (maybe with javascript) so if there is a change in the footer, I can make it once rather than 10 times?

Thanks! Kelly

2 Answers

Stephen O'Connor
Stephen O'Connor
22,291 Points

Use a php include. Add your header/footer code to a file and save it as a php file, site-header.php for example, then add the following code to your page(s) - which will also need to be saved as php files - and the header/footer will be included.

<?php include( 'includes/site-header.php' ); ?> // change the path name to suit your project
Jeff Lemay
Jeff Lemay
14,268 Points

I second this. Just a little bit of php will make your life so much easier.

Check out the first two sections of Build a Simple PHP Application (really just the second section, first is an intro to php).

Kelly Walsh
Kelly Walsh
3,642 Points

Great! Thank you so much!