One of my weirdest passions is understand how server side scripts do all the job in their system application. Mostly to learn something new, borrow useful helpers or just try to understand the human behind the code… Nah, is just to see different way of coding.
I’ve saw a lot of scripts but something that keeps looking so well for me is how WordPress template system works. Don’t take me wrong… WP is very nasty, overly patched, etc. But they have managed to understand perfectly (in my opinion) how to do a template system, at least for PHP. Is that simple that even corporate sites are built in WP just for this (and maybe the plug-ins).
The WP template system rely in direct PHP interpretation. Is not like other template systems where the templates are evaluated (eval function, sprintf, etc) which grants you all the flexibility of PHP because you can run any PHP code in a template file. This could be risky in a template system because users could just use the back-end variables, arrays, objects, but in WP they added the Template tags.
The template tags (helpers and shortcuts to core functions) grants this template system a new layer where you can easily tune and customize the front-end without messing the back-end and with the benefit of full flexibility. So, instead of doings thinks like echo $post[“id”]; you do “show_post_id();”. There are a few other goodies like The loop which when you understand it is like magic (when you understand how to replicate it, not just use it).
When themes was a must for Chevereto, without any doubts I went for WP way of doing themes. I spent a few days reading the code, understanding the basics, etc. Before this I’ve already worked a lot with the WP template system, without caring how works. This time was different because I notice all the crossing wires in WP and all the sea of patches. But I was smart enough to notice that a theme system like that could escalate to anything.
Something that few people know is that Chevereto.com (yes, the website of the script) runs a modified version of Chevereto built up just tweaking the templates. The system is that simple. Well, it helps a lot that I know it like the back of my hand.
Now, the important thing of this post is that just like some people use WP for corporate websites, you can use the basics of his template system for prototyping. The question is… Why?. Why you want that when there is a lot of prototyping tools out there, for any server/client side language?… Easy, speed and flexibility.
In fact, a framework is an excellent tool for prototyping but you have to follow its documentation and you have to adapt your way of programing to it. I feel that the main thing that I hate about frameworks is that and that you don’t play directly with the code… Boring/lazy people.
Instead of that I use the principles of the well known Front Controller pattern, my very own class collection and the template system. So I keep coding on my way, I can do anything I want and I can patch the system anytime and the template system layer keeps things in order and is flexible enough to put nasty PHP code directly. In other words, I have my own framework with WP inspired template system for easy prototyping.
So what is my point? Build your own framework with something like WP template system and you will be able to ultra fast prototyping and develop… Without feeling guilty.