Easy templating in PHP
Even though the subject of “Using templates in php” is everywhere, it still didn’t reach it’s true potential.
Most people who are new to php(not sure about more advanced php developers) use methods like this to put templates in their website:
1 2 3 | < ?php include 'header.txt'; // A simple include ?> |
As you can see it’s not very sophisticated, and you can use it only with normal HTML files.
People who are more advanced use this:
1 2 3 | < ?php include 'header.php'; ?> |
It’s almost the same as the first one, only that you can also put in there PHP code.
The problem with all of those is that as more parts in your template you have the more files your’e going to need.
So if you have three parts like:
head
menu
footer
Then your’e going to need three files:
head.php
menu.php
footer.php
And the more parts the more the files to maintain, So if you’ll need to change one of those file’s name on a 100 paged website your’e doomed.
So what I came up with about one year after I learned php is using one file for all your templating needs.
Read more…
Comments