Package Proposal: HTML_Template_xTemplate
| From: | Dmitri Vinogradov | Date: | Sat, 19 Jul 2003 11:22:19 +0000 |
| Subject: | Package Proposal: HTML_Template_xTemplate | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-18423@lists.php.net to get a copy of this message | ||
Hi .*
My name is Dmitri Vinogradov and i want to present xTemplate engine
(oops... i think this name was already in game)
Oh yeah... another Template engine... ;P
well... I have read the thread above and will try to answer the question
"Do we really need yet another template engine?". I was...
At first - what is it:
xTemplate - is a Namespaced template engine with xsl-like syntax:
Repetition:
<x:for-each select="whatever">... </x:for-each>
Conditional Processing:
1. <x:if test="whatever >= '34'">...</x:if>
2: <x:choose>
<x:when test = "whatever = '34'"> ...</x:when>
<x:when test = "whatever = '35'"> ...</x:when>
<x:otherwise> ...</x:otherwise>
</x:choose>
Variables:
1. <x:value-of select="whatever" />
2. {x:whatever} (why this?? -
ok... to see the variables in WYSIWYG mode..? whyever ;)
Template source can be:
file (default): $srcMethod = 'xTemplate::file'
custom source: $srcMethod = 'customClass::customMethod' - from
DB... throught SOAP... whatever
source as string: $srcMethod = 'source' - the possibility to pass the
template
source to template engine as string
What about data to apply to template...
xTemplate works with objects, array of Objects and
1. Object can be applied to template engine as parameter of
$this->proccess('template.htm', $object);
and / or
2. Object can be applied to template engine through template syntax:
<x:template match="cms::getPage()">
<x:value-of select="title" /> - the value of $object->title
<x:value-of select="author/name" /> - the value of
$object->author->name
<x:for-each select="links">
<a href="{x:url}">{x:name}</a> - the value of
$object->links[n]->url and $object->links[n]-name
</x:for-each>
<x:for-each select="cms::getLinks()">
<a href="{x:url}">{x:name}</a> - the value of
$objects[n]->url and $objects[n]->name
</x:for-each>
</x:template>
<x:value-of select="cms::getPageTitle()" /> or
{x:cms::getPageTitle()}
<x:if test="cms::getPageTitle() != ''">...</x:if>
similar <x:when test="cms::getPageTitle() !=
''">...</x:when>
Internal functions (concat(), mod(), position(), last(), sum() and
other) are implied
and can be extended:
<x:for-each select="cms::getLinks()">
<x:value-of select="concat('the length of url is ',
string-length(url), 'charackters.' )" />
</x:for-each>
Why namespaced?
Well.. following scenario:
One application, lets call it Main application, - is CMS and does whole hard
work -
apply content to template. But the website is heavy visited - about 1000
hits in sek (what a luck ;))
So it makes no sence to run it dynamicaly - the parsed content will be
stored in DB or
as file or whatever once content has changed (one time a day or one time a
year?) ...
But we extends the website with shop layer and - what a problem - the
prices must be shown dynamicly ...
Main application has namespace 'x' (<x:template ...) and shop modul becomes
namespace
'y' (<y:template...)
so the hard work (done by Main application) still parse the content once
its changed,
but the shop layer parse its namespace dynamicly - and so on ...
<x:template match="cms::getPage()">
<y:template match="/">
<x:for-each select="products">
<li>
<a href="{x:url}">{x:name}</a> - Price:
<y:value-of select="shop::getPrice('{x:product_id}')" />
</li>
</x:for-each>
</y:template>
</x:template>
parsed content within 'x' namespace:
<y:template match="/">
<li>
<a href="http://host.com/someurl">Product 1</a> -
Price:
<y:value-of select="shop::getPrice('1234')" />
</li>
<li>
<a href="http://host.com/someurl">Product 2</a> -
Price:
<y:value-of select="shop::getPrice('5678')" />
</li>
</y:template>
parsed content within 'y' namespace:
<li>
<a href="http://host.com/someurl">Product 1</a> -
Price:
$12.34
</li>
<li>
<a href="http://host.com/someurl">Product 2</a> -
Price:
$56.78
</li>
Why xsl-syntax?
well... xTemplate is NOT a try to write XSLT-processor with PHP ...
But
a. its easier for ppl who's already familiar with xsl-syntax
b. and if you have ever tried to explain template syntax to designer,
who
worked just with Dreamweaver in WYSIWYG mode - its really hard...
this kind of syntax (xsl-like) you can add as third-party syntax to
Dreamweaver - define all possible attributes - and explain to
designer who to switch to source mode ("wow - it looks strange")
and how to use it - the life becomes easier... ;)
Ok.. Now to sources
pear install http://uglysite.net/HTML_Template_xTemplate-0.1.0.tgz
or download it directly from
http://uglysite.net/HTML_Template_xTemplate-0.1.0.tgz
in docs/HTML_Template_xTemplate/examples/ you'll find example.php
to see engine at work...
Regards
DV