Computer Science Canada Templating Engine: avioding bottle neck. |
Author: | Craige [ Sat Dec 23, 2006 4:45 pm ] | ||||
Post subject: | Templating Engine: avioding bottle neck. | ||||
Technically, this thread could go in the PHP help forum, but I am not asking for help with the language specifically, but rather a code design. Thus, I have posted it here. So my problem is in a potential design for a website templating engine I'm working on for a new site. I was wanting to do a recursive variable replacement function to the class, however my problem is with how to design it. I wanted to do a recursive function, but I'm not sure how much this is going to bottle neck the script on me. The template file which includes a recursive replace might look like so:
And what the templating engine would do is take a copy of the entire block, and use it as the template to replace variables in, x number of times. Each time, appending the result block to a static temp variable. The recursive function would work something like so:
I fear this will leave me with a huge bottle neck, which I want to avoid. I haven't worked out how all the code will work yet, but I think you can see what I want to do. Ideas? Opinions? |
Author: | wtd [ Sat Dec 23, 2006 6:11 pm ] |
Post subject: | |
I'm curious as to whether this is an academic exercise. Templating engines have been done so many times, and there are so many good ones out there that I fail to see why you wouldn't just learn one of those. Of course, there's nothing wrong with it if it is an academic exercise. I'm just curious. |
Author: | Craige [ Sat Dec 23, 2006 6:31 pm ] |
Post subject: | |
Nah. I've never even taken an academic course on programming. This is for personal use. And the reason I don't use a prebuilt templating engine is simply for two reasons: 1) I enjoy learning new thins like this. Every experience helps you out later in life. 2) I generally don't use any prebuilt libraries for my personal, closed source sites. I don't have any problem using them in Open Source things I may do, but if nobody else is going to see and/or modify it (outside of a small team of coders), I prefer the code to be all original. It just means I know it in and out, and can customize it easily. |
Author: | wtd [ Sat Dec 23, 2006 7:41 pm ] |
Post subject: | |
For simplicity, I would suggest having your templating code look absolutely nothing like the HTML you plan to embed it in. Consider Perl's Template Toolkit for instance, that uses brackets instead of less-than and greater-than symbols. |
Author: | Craige [ Sat Dec 23, 2006 8:10 pm ] |
Post subject: | |
wtd wrote: For simplicity, I would suggest having your templating code look absolutely nothing like the HTML you plan to embed it in.
Consider Perl's Template Toolkit for instance, that uses brackets instead of less-than and greater-than symbols. Actually, I'm using those due to the fact they are HTML comments. If I don't use a variable for some reason, it gets output as a comment. No big deal. Though in the programming scope of it, I should do something with every variable regardless of whether I want to display something or not. |