First, let's decide on our database structure. For what we need to do, we only require one table, which will be called "templates," which will contain -- yes, you guessed it -- our templates. It's a very simple table and only has 3 fields.
To create this table, you can use the following SQL:
Now we will populate it. We will only have 2 records, page_header & page_footer. These will be used to display the <html>, <head> and other needed tags in the page. This is simple so that you can understand what is happening, in reality, these would include logos, menus, and other elements. The advantage of this is that there is only one place where you edit the layout of your page, instead of having to do it in each HTML file. Anyway, here's the SQL:
Let's go through page_header, which consists of the following html:
As you can see, this includes a PHP variable, $pageTitle. These will be defined in the code before we display the template. But we'll talk about that later. Now we have the database schema ready, we can start the basic functions for grabbing the template from the database. template.php The following code is in the file 'template.php':
This may seem a bit confusing, so I'll go over some parts more closely.
blog comments powered by Disqus |