Hello,
This is probably going to be a fairly long post, but please bear with me.
I have a site that consists of roughly 1700 individual pages. Including included SSI files, it's probably more like 3x that. I'm redoing the entire site in PHP and a new design simply because I want the capabilities PHP offers, plus the site was built over the past 4 years, so there is such a mishmash of code in a ton of different technologies that it's not even funny.
So I want to use a template system - basically one which would separate most (if not all) of the HTML from the actual content of the page. Of course, we'll never really get rid of it, because of links in the text and whatnot, but we will do the best we can.
The problem comes when you try to use these template systems listed here on PHPBuilder - they seem fine if you're going to have experienced PHP programmers building and maintaining your site - but what about sites like mine that have people that only know the HTML?
Plus, since all the text has to be assigned to variables, you have to sit there and escape every quote in the entire document, which is a huge pain in the rear (can't put it to a variable unescaped or it will error out).
So I'm a pretty experienced PHP programmer, and I'm trying to come up with an elegant, simplistic, and easy to use way to solve my problem. I don't want to store all the content from the pages in a database because that way, each page would be created dynamically, which would mean it gets looked over my most search engines. The only workaround I can see for this would be to have a way to take all the data from the tables and spit it to separate HTML files - which isn't really a big deal, but considering the number of files I have, this would kill the server if we had to make even a small change to the HTML design.
Then take into account the fact that many of the pages actually have PHP code in them, so the PHP code would have to be stored in the DB as well - and that's a huge pain, because I'd have to finalize my PHP code and then save it to the db - no more editing text files if I want to make a change, I'd have to do it through a web form to update the db - I then lose all my nifty editor features like syntax highlighting and shortcut keys and whatnot.
So what other way is there to separate data from the PHP code, plus leave room for future expansion and easy changes? I came up with a very easy way to actually have this, the problem is that it requires two files for each ONE document 🙁 Here, I will explain what I have in mind.
First you'd have the "xml" page (using this term "xml" because I don't know what to call it - it's not true XML but it uses the same basic ideas - even if you're not familiar with it, please keep reading, this is in no way very complex).
Generally, you'd have a page like this in HTML/PHP:
<head><title>Page Title</title></head>
<body>
<p>paragraph</p>
<? php code here ?>
</body>
Now you see the problem - I'd have to have all this HTML code in each one of my 1700+ pages - so if I wanted to make a design change, I'd have to do it to every freaking file!
Now here is what my "ideal" document would look like:
<title>Title of Page Here</title>
<paragraph>Paragraph text here.</paragraph>
<image src="blah.jpg">
<paragraph>More text <link href="blah.html">blah.html</link></paragraph>
<?php
// Insert all my PHP code here
?>
<paragraph>More text.</paragraph>
Now, as you see, these are similar to HTML tags, but not really - because they are all actually defined in another file I could create that would be included in every page. The thing is, I could set exactly how I wanted each thing to look in a separate file - so if I made a design change, I would just have to change one file, not every single one.
Now, with this example, I'd have to upload like contentpage.xml (which contains the info like you see pasted above) and then contentpage.php (which will simply evaluate the code above, then parse the XML [which means doing a simple str_replace on the quasi-HTML tags]).
A more elegant way to do this would simply be to have PHP first evaluate the PHP code, then go in and do the str_replaces for the fake XML tags - but it would be best for PHP to be able to do this without requiring a separate file each time 🙁
Hell, I could probably write a C++ program to do the searches and replaces after PHP has done it's work, but I'd have to get PHP to somehow pipe the data to an external program before it spit it out to the browser - which would then increase overhead, blah blah blah.
Any ideas to get a template system that's workable for my site? One that separates the data from the HTML, plus allows PHP code to be inserted, plus is easy enough to look at that only semi-proficient people wouldn't have too hard a time with?