RE: RE: [PEAR] PHPTAL - PHP Template Attribute Language
| From: | laurent bedubourg | Date: | Thu, 13 Mar 2003 13:26:37 +0000 |
| Subject: | RE: RE: [PEAR] PHPTAL - PHP Template Attribute Language | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-14240@lists.php.net to get a copy of this message | ||
Le Thu, 13 Mar 2003 09:40:54 +0100, Sebastian Bergmann a écrit :
> Lukas Smith wrote:
>> Sounds nice.
>
> Sounds like the XML Transformer to me.
Nope, it is a ready to use TAL/METAL/I18N/TALES implementation for PHP.
I've just look at XML Transformer and it looks like a good callback based
XML parser to me (with interesting implementations for docbook and other
systems).
May be a way to instantiate "element handler Classes" as a callback
alternative to "start_* and end_*" functions would be interesting...
That's why i usually prefer generic onElementStart-onElementEnd-onData
xml parsers, i get more freedom with less code, but like the latin proverb
says :
"des gustibus et coloribus non disputantum".
Even as an XML parser, XML Transformer would have been of few interest for
PHPTAL as TAL language is based on Attributes and not on Elements.
That's the main difference between TAL an any other template systems,
that's why it's called :
"Template Attribute Language".
Let's give an example :
<span tal:content="myobject/myMethod/10/foo">
this text is a sample that will be replace by the evaluation of
myobject/myMethod/10/foo in the current template execution
context
here and for example myMethod returns an array an we use the 11th item
which may be
- an object having a variable named foo or a method named foo,
- an hashtable with a key named 'foo'
</span>
Another one for the road :
<table>
<tr tal:repeat="item some/iterable/resource">
<td tal:content="repeat/item/number">1</td>
<td tal:content="item">the item value here</td>
</tr>
<tr tal:replace="" tal:comment="sample line just for wysiwyg rendering">
<td>2</td>
<td>foo</td>
</tr>
<tr tal:replace="">
<td>3</td>
<td>bar</td>
</tr>
<tr tal:replace="">
<td>4</td>
<td>baz</td>
</tr>
</table>
I just can't leave without writing this one (with more example tags):
<p tal:repeat="link php:get_links(myDoc.Id)">
<span tal:comment="If the link has an xhml value (may be an image or
any other xhtml) we output this value,
we use 'structure' keyword to prevent it from been
htmlencoded()."
tal:condition="link/xhtmlValue"
tal:replace="structure link/xhtmlValue"
/>
<a tal:comment="If the link has no xhtmlvalue, we create the link
here.
We also provide a sample link for wysiwyg preview.
tal:attributes allow use to overwrite sample
attributes."
tal:condition="not: link/xhtmlValue"
href="http://www.example.com"
class="somecssClass"
tal:attributes="href link/href; title link/title"
tal:content="link/text"
>sample link</a>
</p>
What's the interest of using XML Transformer for this implementation ?
i'd have to implement every html / xml / unknown elements possible o_O
that make no sense.
I prefer using a more abstract xml/xhtml parser, nothing very
interesting just xml_* wrapped in an object.
What's interesting is the implementated features for php coders and
template designers, not the xml parser (since it seems to work)!
I hope it's now clear to you that PHPTAL has many more features than
what you seems to think, xpath like data access, macros and slots,
php intermediate code generation, abstract output caching interface,
XHTML or XML output, internationalization (translation) support with
variable interpolation, attribute based expression syntax, other
features related to each attribute role (repeat, condition, on-error,
...),
and the most important :
it benefits from more than 2 years of zope developers,
template designers and users work, tests, documentation, feedback
and thinking.
The first time one of my friend show me TAL, i was sceptic, then i saw the
doc, then i made some tests in python, then i decided to create PHPTAL.
In fact, there's only one way to describe TAL/ZPT :
"Touching TAL is adopting it !"
And when you adopt TAL, you want to use it whatever the underlying
language is (python, perl, java, php). And you quick forget the
uggly non previewable XSLT and other obscures template systems
believe me and all TAL users. And if you don't, just give it a
try... it's free :)
(warning: TAL is also a Template Addictive Language)
And if you still doesn't see the interest of TAL, well may i be punished
by the first one who doesn't see the interest of TAL after reading
documentation, doing some templates that works, begining with the
tal:content tag, then the tal:replace, then tal:condition, etc...
As a punishment, i'd like some bug reports, whish lists and feature
request :)
Most information is on :
http://www.zope.org/Wikis/DevSite/Projects/ZPT/FrontPage
For some examples and docs about PHPTAL :
http://laurent.bedubourg.free.fr/php/phptal/Documentation.txt
PHPTAL home :
http://laurent.bedubourg.free.fr/php/phptal/
Current version (at the moment i write this message) is 0.4.0.
I still have more tests and clean-up to do before a stable release.
best regards,
i hope you just had some kind of first wrong overall impression :)
laurent
--
Laurent Bédubourg
laurent.bedubourg@free.fr
PHPTAL home http://laurent.bedubourg.free.fr --
testers welcome