Created
January 19, 2012 02:18
-
-
Save rmasters/1637232 to your computer and use it in GitHub Desktop.
Templating example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Two directories: | |
/public -> For publically accessible files | |
/templates -> For templated code, not publically accessible | |
Make pages in /public which have database/$_GET/etc. code in them (business logic/controller logic). At the end of them do: | |
$contentPath = __DIR__ . "/../templates/index.php"; | |
require __DIR__ . "/../templates/layout.php"; | |
Where index.php is the name of the template you want. | |
Then in templates, create a /templates/layout.php like: | |
<html> | |
... headers, blah ... | |
<?php require $contentPath ?> | |
... footers blah ... | |
</html> | |
This is your layout that has content for every page. Then create a template (/templates/index.php): | |
<p>this is the index</p> | |
When you go to /public/index.php, it will include /templates/layout.php, which in turn includes /templates/index.php. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment