RFC: xipe enhancement
| From: | Sam Liddicott | Date: | Wed, 09 Jul 2003 12:54:07 +0000 |
| Subject: | RFC: xipe enhancement | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-18099@lists.php.net to get a copy of this message | ||
I'm requesting comment on a new templating enhancement I thought of and am
working on, which I wish to contribute to XIPE.
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