One of the magic words of flexible programming is... say it with me now... declaratively. The more things you can specify declaratively -- in other words, what you want to happen rather than how -- the more flexible your program will be. That's why there's so much work with declarative languages, and why they can be so powerful. Furthermore, this is why regular expressions are so powerful, and why SQL is so powerful, etc.
But principles of declarative programming go far beyond the style of the programming language you're using. For instance, any time you can use a configuration file instead of something hard-coded in your code, it's far more flexible. Something in a configuration file that looks like foo=bar may look the same as something in code: foo="bar", but there's a big difference.
For my CMS, the templates are structured differently than anything I've seen. Rather than writing an HTML-looking template file with lots of "code" in it (things like "loop through all addresses, and print the name, address1", etc.), the templates have "sections" which simply serve as an anchor for content to go in. The sections can be filled in with any combination of "view components" or sub-templates, and maybe eventually actual output so you can specify what you want directly rather than having to have a view component for very simple things.
Then, in a configuration file, you just say (declaratively) "print my blogroll", "print my recent comments", etc... in other words, you can just specify the name of the view component you want. Right now, the "view components" are simply PHP functions that take data from the model and output whatever. But it's not ultimately limited to this. I could just as well specify the view component in a sub-template parsed by Smarty and compiled into a resulting PHP script.
I hope this will give me all the flexibility I want. In existing template designs the particulars of the data you're printing out are too tied to the template. In my system, you have instead a view component that is tied to the data given by the model, but the template doesn't have to know anything about what its sections are being filled with. Note that the sections can be as fine-grained as you want them to be, with a section for every view component that you're printing as the degenerative case, but usually with multiple view components for each section.
When I finally get all of this done, I'll probably have fun providing demos where I radically change the content of a page just by changing things in a configuration file.
The one downside is that currently the view components have to be specified as PHP functions. I don't currently have anything nice and neat like in MovableType. But, I haven't had to write my own template language
, and maybe I can do something nifty with Smarty after everything is working neatly.
By the way, this is why I was so upset the other day that PHP doesn't have any kind of compile-time include. I have to use something like Smarty to get that kind of functionality.
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):