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 trialKelly Walsh
3,642 PointsBuilding 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
22,291 PointsUse 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
Kelly Walsh
3,642 PointsGreat! Thank you so much!
Jeff Lemay
14,268 PointsJeff Lemay
14,268 PointsI 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).