Skip to content

Instantly share code, notes, and snippets.

@rmasters
Created January 19, 2012 02:18
Show Gist options
  • Save rmasters/1637232 to your computer and use it in GitHub Desktop.
Save rmasters/1637232 to your computer and use it in GitHub Desktop.
Templating example
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