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
https://forums.phpfreaks.com/topic/207092-php-template-based-pages/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.