Jump to content

PHP Template-Based Pages


johnsmith153

Recommended Posts

I want to setup a website and structure a template to prevent page/code duplication.

 

I suppose I could do a simple system:

<?php
//index.php
include('everything.php');
include "htmlHeader.php";//would include HTML doctype and head tags + opening <body>
$page = $_GET['page'];
include "pages/".$page.".php";
include "htmlFooter.php";
?>

 

How would I change this template so I could add extra PHP / JavaScript includes to certain pages only (e.g. a function to access a database would be in the everything.php file, but a one-off PHP function wouldn't be). All pages/pagename.php are loaded after HTML output.

 

Or do I need 3 page includes:

1. before HTML output for one-off PHP

2. In the <head> tag for one-off JavaScript

3. the one just like above in the <body>

Link to comment
Share on other sites

Just by including or echoing something that output isn't sent to the browser. In the script you provided there would only be 1 output to the browser (at the end of execution) as is the case in most situations unless you're using output buffering.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.