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.
Not particularly my style. If there's anything beyond presentation logic in the "PHP CODE" bits, I would say not a good design. However, I wouldn't be a stickler if building it real quick for a proof of concept or something. Anything else, it'd likely get a frown.
To me, it feels natural for small or medium proyects, but is it really a good design?
In my opinion it's a spaghetti since I'm guessing "PHP CODE" includes logic. If the "PHP CODE" is something else then it's still a bit messy since you've got to escape all backslashes. If you were going to use vagualey that schema I'd at least use heredoc
My idea of a template would not include any logic at all and would look like HTML. The logic can be done externally (in a controller?) and the syntax can easily be based around HTML
That said, templating really is one of those areas lots of people disagree on so I just say use what feels right to you
I really prefer to keep the code and the HTML separated into different scripts -- except in PHP templates. I just find it much clearer to see what the code is doing. And I find that mixed PHP/HTML hides bad design. I really think of PHP as two languages, a programming language and a template language. When used as a templating language it is usually just conditional and looping constructs and read-only access to objects and vars.
I do separate php from html, but well, not 100% because I cant. I have to construct tables in the php files. I store them in $CONTENT, so the tables are then passed to the template.
Though there are some scripts in which there are FAR more $CONTENT varaibles to apprend. Any tips? Maybe my design is completely wrong. I must tell you... I *am* a newbie, so comments are very appreciated...
I'm making a different approache then Smarty for example and i got an overall speed improvement also.
If you are planning to make a template system is better to allow some cycling functions instead of adding fragment of templates.
I'd like to see a really small, simple set of template classes, the first that just does "{myvar}" replacement like danf_1979 showed. Then a second class that adds, say blocks. And a third that adds if() conditionals and while() loops (and I guess for() and foreach()). Then you could just include what you need in your View, but could change up or down because they share the same interface. And it should be customizable so that people could use "{" or "<<:" or whatever prefix/suffix they wanted.
Templating is one of the major PHP (actually, many server side scripting language) debates. Take a look at phpBB. They developed a templating system built on the phplib platform. For Olympus they have adapted their teplate class to use a Smarty type syntax. Then look at WordPress. They don't use templates at all (in the way that most think of templates). They use an html page with PHP function calls placed strategically throughout the page, which is parsed at the end of the page.
I suppose, as with the debate on OOP vs. Procedural coding or the debate on coding standards, use the system that feels best to you while at the same time offering you the best performance for your scripts tasks.
<puttingmytwocentsin>I use the phpBB template class for many apps, though I am testing an app right now that uses a system like WordPress. I like them both.</puttingmytwocentsin>
Well, I'm developing a CMS at the moment which uses entirely CSS based templating. I made a templating class which I call and use throughout. The script passes which style sheet to use to the templating class.
The HTML is all written inside the templating class, which does all the logic too.