Re: RFC: xipe enhancement

From: Date: Thu, 10 Jul 2003 01:34:51 +0000
Subject: Re: RFC: xipe enhancement
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-18109@lists.php.net to get a copy of this message
Sam Liddicott wrote:
I'm requesting comment on a new templating enhancement I thought of and am working on, which I wish to contribute to XIPE.
Interesting idea.. - you know that you could add this in about 10 lines of code to Flexy? - just modify the toHtml part of HTML_Template_Flexy_Token_Tag to check for the method attribute.. and store the methods in a static global... then output later.. For the method variable intopolation to work.. ,you would probably have to parse and add the variables from the method call to the available variables in the engine (theres and example in the foreach token from what I remember) yes - normally using namespaces for custom attributes is a good idea - most of flexy's custom attributes / foreach.. etc. use flexy:foreach prefixes. I did think about something like this for 'blocks' and defining funcitons or something. but ran into problems deciding on naming conventions. What strategy did you have for naming the classes, as if you have a fixed name, you cant load two pages into the same request. and md5'd class names means extending/overriding them is difficult.. Regards Alan
I've tried various content management systems and templating systems and come to the conclusion that most of them use PHP to implement a set of rules more unweildy and un-natural than PHP itself, and thus score an own-goal. XIPE is the only template system I am pleased with and was inspired to offer these improvements after bashing my head against typo3 for a while, it contains in some way the main useful and accessable feature of typo3. It turns out what I produced is something similar to .net webforms, but webforms go too far IMHO (by trying to write too much code in tag attributes). I have some php which parses html templates which have some extra markup and then defines a php class which when instantiated will generate the same page, but with the advantage that the generated class can subclass an existing class and the generated class can also be subclassed. So we get full design extensibility without embedding logic in the design and risk breaking the logic as the design is changed, and without embedding design in the logic and risk breaking the design when logic changes. Here's an example html template with some markup (I would like to merge markup rules it with xipes intended template directives) <html method="page"> <head method="head"> <title call="showTitle" method="title">Default Title</title> </head> <body method="body"> <table><tr><td><div call="navs"> <span method="nav" nocall><a href="XX">YY</a><br/></span> </div></td><td> <div method="content"> <h1 method="caption"><?php echo $title; ?></h1> a b c <p> more </p> </div> </td></tr></table> </body> </html> It generates this class definition: <?php # Automatically generated by generator (c:\apache\htdocs\metatemplate\mt\generator.php) class basepage extends rawpage { function document() {
    $this->page();
} function page() { ?><html METHOD="page"><?php
    $this->head();
    $this->body();
?></html><?php } function head() { ?><head METHOD="head"><?php
    $this->showTitle();
?></head><?php } function title() { ?><title CALL="showTitle" METHOD="title">Default Title</title><?php } function body() { ?><body METHOD="body"><table><tr><td><?php
    $this->navs();
?><div CALL="navs"><?php
    $this->nav();
?></div></td><td><?php
    $this->content();
?></td></tr></table></body><?php } function nav() { ?><span METHOD="nav" NOCALL><a HREF="XX">YY</a><br></br></span><?php } function content() { ?><div METHOD="content"><?php
    $this->caption();
?> a b c <p> more </p></div><?php } function caption() { ?><h1 METHOD="caption"></h1><?php } } ?> Notice that where-ever a new definition takes place in the template, further output is directed to that method body and into the previous method body is inserted a call to this method. Notice that for the "nav" tag no function call is made (nocall directive), but just above the "nav" tags a "navs" call is generated. The parent class "navs" method makes repeated calls to the "nav" methods defined here. This is one instance where traditionally either loops are embedded in the template or html markup is embedded in the programmers php. The caption and content methods will be over-ridden - or could have been defined in the parent class and merely called in the template but I don't prefer that approach. Further development: I wish to follow alternative XIPE style markup outside of tag attributes for those editors or users that can't manage tag attributes. I wish to support XIPE embedded echo statements AND automatic variable use recognition: Note than for the "nav" method definition we actually need to pass the href and caption for the nav links somehow. The template should probably have said: <span method="nav" nocall><a href="{$url}">{$label}</a><br/></span> Should these be automatically detected parameters so that the method becomes: function nav($url,$label) Or automatically detected members of a hash passed as a parameter? function nav($vars) and then of course {$url} would need to be expanded to: $vars["url"] - this would be less troubled by change in parameter order... maybe <span method="nav($url,$label)" nocall><a href="XX">YY</a><br/></span> to specify? Feedback and preferences aprpeciated here: Maybe we should remove our custom attributes from the generated output? Can attributes have namespace prefixes? I also think that MAYBE sometimes we want the defining tag to be output seperately to it's body; e.g. does the <title> tag want to be part of the title method, or should I have been doing: <title><faketag method="titletext"> ..... or should tags have the option if the tag should be included in the generated definition? If you want to look at the code I'm using, the current proof of concept is at www.liddicott.com/mt.tar or www.liddicott.com/mt.zip I just switched to my own html new parser in place of the xml parser so we can cope with old and bad html, I'm now giving my html parser a decent interface so don't feel compelled to improve it just yet. The parer doesn't cope with <? tags or un-parsed CDATA tags yet cos I forgot about them, but don't worry about that yet. Just for interest, I use php-eclipse as my ide. Sam
-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com

« previous php.pear.dev (#18109) next »