Re: [SMARTY] Smarty TAL Compiler

From: Date: Wed, 07 Aug 2002 21:05:47 +0000
Subject: Re: [SMARTY] Smarty TAL Compiler
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5616@lists.php.net to get a copy of this message
--- Craig <zzd@nc.rr.com> wrote: > I think your idea to create the equivalent of zopes > TAL is great Thanks:) >, but why > would you build a template engine to be parsed by > another template engine? When I tried this the first time round, I used expat and created a replacement parser to smarty's default one. It worked all right, but required the templates to be strict xhtml ie <input type="text" /> rather than <input type="text">, <br /> instead of <br>. Frontpage for one doesn't create this type of markup (infact worse still it creates invalidly nested markup) I asked the designers at work what they thought about manually going through the html and that's when the project hit the rocks:) I also tried creating prefilters to correct invalid html before sending it to the compiler but it just got really messy and doesn't cure invalid nesting. Another problem with creating a custom smarty compiler is that there's alot of smarty features for which there's no direct equivalent in zope tal (eg {include}, {include_php} etc) So, having thought it through again, I think that the best way (and i think Monte suggested this before) is to create a prefilter to convert tal attributes into smarty code and send that to the smarty compiler. This way you can use both the tal syntax and the smarty syntax together, as appropriate. If we can't use expat to parse out the tal attributes then consider using regular expressions to do the job. It's not as easy as it seems though, because you have to allow for nested tags. eg... <table> <tr tal:repeat="$people"> <td tal:content="$smarty/repeat/name">Richard Wall</td> <td> <table> <tr><th>Age</th><td tal:content="$smarty/repeat/age">25</td></tr> <tr><th>Address</th><td tal:content="$smarty/repeat/address">Coventry</td></tr> <tr><th>Link</th><td tal:content="$smarty/repeat/url">http://www.cwndesign.co.uk/</td></tr> </table> </td> </tr> </table> ...you might write a regexp like... ¬<([^\s]+)\s+[^>]*tal:repeat="([^"]+)">.*?</\1>¬ ...but it would stop at the first nested </tr> and in greedy mode, it would grab too much. You might also think that it's similar to having nested {foreach}{/foreach} in a normal smarty template (i did:) and try to see how Andrei/Monte coded round it, but it's not the same, because in this case you always want to output a certain php string when you hit the end tag (I think). So I started trying to keep a stack but then realised that all I was doing was rewriting what has already been written for the html parsers in Mozilla / IE etc. Conveniently, the IE html parser can be accessed as a com object ('htmlfile')... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/135702 ...there's even a mozilla activeX componant that has the same interface as mshtml... http://www.iol.ie/~locka/mozilla/mozilla.htm ...but it's not finished and although it says you can use it for DOM manipulation, all the examples seem to be for delphi. (It's used for the preview in Bradsoft's Topstyle) I thought that there might be a Mozilla / Gecko PHP extension, have not so far found anything. (I'd love to write one, but wouldn't really know where to start:) Also don't currently know much about the sablotron extension, but doubt if it can handle normal invalid html. Anyway I'll let you know if I make anymore progress with my soap version, or if I find a way of doing it in PHP. -RichardW. __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com

« previous php.smarty.general (#5616) next »