Jump to content

templating dilemma


drtanz

Recommended Posts

hi i am making a php site and have really become confused about templating.

 

Right now I have the following:

 

A CSS styling file including text formatting and item positions

A php 'template' file containing static text and images that should appear on every page

Various php files containing php code and html for performing various functions in my cms and displaying the results

 

The php files do very basic formatting so my idea was to have the php template file as the base for all pages, and passing a variable to it depending on the menu selection which will tell the template from which php file to extract the main content.

 

I dont know if this possible however and would like some guidance as to which way i should be doing this. I also read about some templating systems that help in separating design from processing but I dont know if this is what im looking for.

 

Thanks and sorry for my confusion please ask if I need to clarify something.

 

Link to comment
Share on other sites

You can do that.. one way to do it is like this:

 

$pages = array(
  'index',
  'news',
  'contact',
);
switch($_POST['page']) {
  case 'index':
    include('index.php');
    break;
  case 'news':
    include('news.php');
    break;
  case 'contact':
    include('contact.php');
    break;
  default:
    include('index.php');
    break;
}

 

It's always best to list the pages explicitly, so people can't access your files by inventing new pages.

 

Another method is with Smarty (what I use).  With that, your templates are stored in seperate files (which are also capable of including each other).  If you have a small project, the php method above is fine.  For larger projects a system like Smarty helps greatly, as it seperates processing from design, as you said.

Link to comment
Share on other sites

I also wanted to ask if the approach you explained for calling pages is better than using dreamweaver's function for making a template with an editable region (to contain the php code) and then applying this template to all pages. Basically this is the reverse approach, instead of including php files into the template, you would be including the template into the php files. thanks

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.