Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
I'm slowly developing a new version of my templating system and am very interested in implimenting a if/elseif/else statement structure in it. IPB and a few other software packages include this feature but are so integrated into the kernel that I can't find anything useful. Something like this:
Btw, if you have a better structure for that scheme then let me know. I'd like to keep it as simple as possible, but if it will keep the processing time down then do whatever works. I'd like to keep everything in Perl Expressions (preg_match, preg_replace, preg_replace_callback). Obviously this feature should include a callback function so I'd advise using preg_replace_callback(), but if you have a better way of doing it, by all means go ahead.
If I could get a working templating class that would process this it'd really make my day. I've been wondering how to do it for ages (literally).
I should have known someone would have suggested Smarty (or the like). I want to develop my own and others, namely smarty, are too bloated for what I like.
phice wrote:I should have known someone would have suggested Smarty (or the like). I want to develop my own and others, namely smarty, are too bloated for what I like.
Sorry, you weren't specific enough. You said you wanted a working template class that worked the way you specified. I did that, but it didnt "make your day".
<{if($x > 10):x10}>$x is more than 10. <{if($x == 12)}>$x equals to 12!<{else}>$x is not 12.<{endif}><{endif:x10}>
Edit: if you find the part of vB where conditional statements is parsed, could you please give me that part? I'm interested in how vB handles nested statements
Personally, I don't like to put any kind of code into templates. The way I see it, html design is a separate skill set to programming and html designers should be allowed to work exactly the same way they are used to ie:
(1) no requirement to learn a new language - even a simplified, custom syntax
(2) templates which render properly with the normal Dreamweaver preview command - no requirement to run the page past a server (which can lead you into all kinds of problems)
That requires some code generation. The designer can be presented with a list of simple, xml-like tags for a particular page (but no loops or conditionals). When they're done designing, the template can be "compiled" ie the tags are swapped out for some php presentation code.
This isn't for a designer, but a production-level, company-owned website. The reason I want an advanced templating system is that I would like to be able to run the whole website through an advanced templating system without having to make .php files left and right. This would allow my partner(s) to learn the language very quickly (no xml, php knowledge required) and not waste any time.
I've managed to make <if condition="--">---</if> and <if condition="--">---<else>---</if> work properly, and am working on <if condition="--">---<elseif condition="--">---<else>---</if>.
Here's what I'm thinking: take Smarty, and start getting rid of functionalities until you get what you want (aka heavy modding). In fact, it's possible the Smarty, with all its extra features, probably has a better track record than your code: it's battletested, and have been tuned. It's obvious that you have no clue how you are going to implement this stuff: more times than not, you're going to choose the wrong path, and that's going to impact performance.
I typically create code that runs much faster in smaller amounts of lines than most conventional software packages. I don't need anything that will work with PHP4, nor worry about security (it's a closed templating system, no one beside my staff will touch it).
But thanks for the post, I've taken that route into consideration before but I believe it's faster for me to just create my own (and learn from it, too) than just hack away at someone else's work.
I think I know what you are getting at Phice. I had to use a similar templating system in a chat system -- Global Chat (formerly iChat). It's old and written in C but it could be configured in just about any way imaginable using <IfTemplate> style tags in the html. Never had to touch any code. Something like this: