PHP include layout template /templating system
- Started
- Last post
- 10 Responses
- Hue
I am trying to create a site with simple PHP, using includes for the header, footer, nav ect. I have managed to set up the simple structure, setting up htaccess to remove the .php from the url, but struggling when getting to sub pages within a section e.g child pages of a section like "fonts/helvetica" as the includes then don't work due to the url change.
Can anyone recommend a simple PHP layout to start from? or a PHP templating system for a very simple site. I would usually build in something like Wordpress which deals with all of this but want something a lot simpler so thought I would build from scratch.
- mekk0
Smarty is a very simple templating engine but for me it makes no sense using them because PHP brings its own template engine.
So what exactly is the problem? Are you getting errors or does the link not work?
- mikotondria30
I would ask the folks at Stackoverflow about fixing the htaccess in this case...
- ETM0
Relative or absolute links in the includes? It's best to always have the path from root so that it work on any level in the hierarchy.
'/includes/header.inc'rather than' ../includes/header.inc' etc.
The url rewrite shouldn't otherwise affect this.
- vaxorcist0
php is pretty easy, but its easy to confuse yourself with .htaccess.
I'd put the include files in a seperate directory, without the .htaccess applied to that directory, so your .php files are still "normal"
- vaxorcist0
usually I do something like:
<?
$headline = "helo world";
$seo_headline="whatever";
include("head.php");
?>stuff.....
<?
include("foot.php");
?>
- Hue0
my hataccess file is just removing the .php with the following code: RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]and my includes are <?php include('includes/header.php'); ?> I have tried defining the root with $_SERVER['DOCUMENT_ROOT'] but it isnt working with pages within a folder e.g fonts/font1
- vaxorcist0
DOCUMENT_ROOT is sometimes flakey.
You could try a variable set....
$mypath="/usr/you/webserver/wher...
- ETM0
If there is no dynamic content in your include files, just use .html or .inc extensions. If you are only rewriting .php extensions/urls, and that happens to be the issue, then you should be good.
- i_was0
"as the includes then don't work due to the url change."
no sense, you're just doing it wrong.