Templating/Expression - if/elseif/else (possible for, while)
Moderator: General Moderators
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
ditto, good luck with your project and let us know how it goesphice wrote:I typically create code that runs much faster in smaller amounts of lines than most conventional software packages.......
.........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.
Are you sure its working right? Try this onephice wrote: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>.
<if condition="11">
<!-- make my outputs -->
<if condition="22">
<!-- we got a special case -->
<else>
<!-- other case -->
</if>
<else>
<!-- printout something else -->
</if>
Regular expressions are nice, but you cannot replace a programming language. You are looking for something like YACC-Bison for PHP. For the things you wanna make you need something like a Scanner and a Parser. U need to read the tokens, create ur syntax tree and than parse through it. You need to define HTML and Javascript tags as tokens, so the scanner is returning the right ID's.
Second Problem is, that PHP is not compiled, so u have to init ur scanner and parser (tokens) every page refresh. This is getting too slowly for todays needs.
And you tell something like "dont need to learn PHP or HTML or something". But they got to learn ur programming language and all the generated problems out of it.
If you want to seperate ur "business logic" from "design", you should remember, that its not seperating PHP-Code from HTML. You want to force the user (programmer) to seperate it because of your template engine. But this is not your problem, its a problem of programming standards. You should tell, how the code should be organized.
At last, if you calculate the time, you spend for the template engine, was it worth it? Always new problems, new functions etc. ? Maybe u think about it :o)
My Template Engine (its not an engine, but a helper class) is based on this excellent article:
http://www.massassi.com/php/articles/template_engines/
So i got for every 'display' file one file for the business logic (saving, reading, sorting, blablabla) and one template file (wich is a mix of PHP-Code and HTML), wich doesn't have function-declarations or something like that. It's only for display with for-next if elseif , rekursions (Try that with any template engine).
And the code is not messy:
Code: Select all
// test.html
<table border="e;0"e; cellpadding="e;0"e; cellspacing="e;0"e; width="e;100%"e;>
<tr>
<th>MID</th>
<th> </th>
<th>Company</th>
<th> </th>
</tr>
<?
for ($t=0; $t<count($list); $t++) {
$merch=merchant_by_userid($listї$t]ї'id']);
?>
<tr>
<td><?=$merchї'MID']?></td>
<td> </td>
<td><?=$merchї'company']?></td>
<td> </td>
</tr>
<?
}
?>
</table>Code: Select all
// test.php
$main=new cTemplate("e;templates/test.html"e;);
$main->put("e;list"e;, $list);
$content=$main->parse();
$template=new cTemplate("e;templates/global.html"e;);
$template->put("e;title"e;, $title);
$template->put("e;keywords"e;, $keywords);
$template->put("e;content"e;, $content);
print $template->parse();