Hi.
I'm hoping that some of you may be able to offer me some advice regarding how to go about creating a template system.
To cut a very long story short, I'm in the process of rewriting my website, and rather than place html and php code in the same files again, I would quite like to add a template system instead. I'd like to store the templates in a mySQL database and output them when required. The only thing that is essential in this system, is that the templates will interpret any variables inside them.
To try and make this a little clearer, I may like to run a mySQL query on my index page, which counts how many users are registered on the site and assign it to a variable, maybe named $totalusers. Then, somewhere in that pages template, I could write "Total Users Registered: $totalusers" which would output the correct number of registered users.
Alternatively, let's say that my index.php file checks to see if there are any active announcements in the mySQL database. In the index template, I would put
$announcement where any such announcement should be shown on the page. Then, if the script finds an announcement, the announcement template is output in place of
$announcement, within the index template. If not,
$announcement is empty and is simply ignored.
Anyhow, I've spent most of the evening working on this, and I can't seem to get anything other than a blank white page when I try to output the template(s). This makes me think that I am on the wrong track, and I could therefore use some advice as to how I should go about doing this.
I'm certain that this is possible, as I've seen it done before. I just can't remember much about it. :-/
I'm sorry I don't have any code to show you, but I've tried so much this evening, that I've completely lost track of what I tried, where I tried it and so on.
However, I feel the best way to learn is through experience, so I am determined not to give up untill I have this system made and working how I need it. So, any advice on this topic would be very much appreciated.
Thank you.
