Page 2 of 2

Posted: Wed May 04, 2005 7:57 pm
by phice
I've already got the best if and if/else done, but thanks for the example. :)

Posted: Thu May 05, 2005 9:55 am
by vigge89
How are you progressing, if you need any help regarding regexp parsing, I'd be happy to help, since I've already done most of the template parser :)

Posted: Thu May 05, 2005 10:01 am
by malcolmboston
phice 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.
ditto, good luck with your project and let us know how it goes

Posted: Thu May 05, 2005 10:27 am
by phice
I just found a book that talks about string maniuplation and has about 100 pages dedicated solely to regex so I'll see what I can come up with within a couple of days.

I'm trying to avoid tokenizing each block but I know it's going to ultimately be my fate.

Posted: Mon May 23, 2005 6:59 am
by Causch
phice 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>.
Are you sure its working right? Try this one

<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=&quote;0&quote; cellpadding=&quote;0&quote; cellspacing=&quote;0&quote; width=&quote;100%&quote;>
  <tr>
    <th>MID</th>
    <th>&nbsp;</th>
    <th>Company</th>
    <th>&nbsp;</th>
  </tr>
  <?
  for ($t=0; $t<count($list); $t++) {
    $merch=merchant_by_userid($list&#1111;$t]&#1111;'id']);
  ?>
    <tr>
    <td><?=$merch&#1111;'MID']?></td>
    <td>&nbsp;</td>
    <td><?=$merch&#1111;'company']?></td>
    <td>&nbsp;</td>
    </tr>
  <?
  }
  ?>
</table>

Code: Select all

// test.php
$main=new cTemplate(&quote;templates/test.html&quote;);
$main->put(&quote;list&quote;, $list);
$content=$main->parse();

$template=new cTemplate(&quote;templates/global.html&quote;);
$template->put(&quote;title&quote;, $title);
$template->put(&quote;keywords&quote;, $keywords);
$template->put(&quote;content&quote;, $content);
print $template->parse();
Maybe you read the article from Brian Lozier and rethink it. And if you look deep inside you, you will see, that he is right. Maybe you should spend your time on the project and not on the template engine, because it's really a waste of time.