This method does not requires any installation of PHP template engines such as Smarty, XTemplate, etc. All it takes is 2 lines in your
Well, how am I doing it?
Sort answer: using Apache directives.
Longer answer: using Apache directives to auto-append and auto-prepend header and footer files.
To achieve this, do the following:
- Create an HTML/PHP file with your design layout.
- Break this file into 3 portions, before dynamic content, content, and after dynamic content.
- Save the before portion as head
er.phpand the after portion as
footer.phpin your server’s root directory.
- In your
.htaccess, add the following lines:
php_value auto_prepend_file /header.php
php_value auto_append_file /footer.php
- That’s it.
Now, create your website as you normally would. Every time your pages will load, Apache will automatically “wrap” them with your header and footer files, producing your desired end result.
I recommend using the .html file extension for the header and footer files to save server load if your pages are not dynamic pages.
PLEASE NOTE: Your webhost may not allow you to use these Apache directives, so be sure to check that out before hand.
Ran Aroussi is a computer developer & designer working with computers and the Internet since 1996. Ran interests include (but not limited to) web development, standards and programming.