Template systems - which method?

Template systems - which method?

am 04.10.2007 17:25:46 von webcm123

I'm looking for a good idea or ready library for templates. HTML with
PHP isn't the best solution (it's more difficult for end-users of CMS
to edit them). Perhaps, everything I need is:
- variables - e.g. {var}
- sections or conditions (some elements won't be printed out)
- loops or selecting fragments*
- cache (recommended for speed)

The template system must be fast and efficient. Most probably I will
create own library for CMS requirement. However, i think about
existing scripts, e.g. XT (XHTML Templates) and OPT (Open Power
Templates).

XT
+ based on XML (DOM functions)
+ templates are clean (without template language)
+ you can modify code properties (e.g. styles, colors, etc.) - DOM
functions are powerful too
+ quite fast
+/- for every template you create new XT object
- no cache (author thinks XT is fast and it isn't needed and XT parses
templates in real-time)
- no {var} support - everything is based on DOM**

OPT
+ cache
+ powerful
+ you are independent of language you use in templates (e.g.
HTML, ...?)
+/- only one instance optClass of template system (you can change
options, etc.)
+/- based on template language ({section=abc}{/section}, {if=...}{$var}
{/if}...)***
- compilation to .php files is slow
- template language can make editing templates more difficult (but
easier as with PHP code)
- large size of library's files

* Loops. In PHP i get news using unbuffered query and read them
through foreach loop.

foreach($res as $news) {...}

Perhaps, for server and script performance, CMS should send one news
after every iteration. There are 2 methods:
- You divide template into fragments and assign new data to "one news"
fragment in every iteration.
- You call a function (which exists in cache) in every iteration.
Eventually, template system can collect these data to put them later
but it uses more RAM.

** I prefer {var} variables. Imaginate that you assign an URL. You
don't know whether template has a link (which is more recommended)
with HREF attribute or whether it has (Google
doesn't probably read it). I don't know other examples but look at
another issue. You want to put some text or other characters. You can
still do it but it isn't so easy:

»

*** I think XT idea is better for code redability. But what with
caching? Is it needed? Remember that you must load template through
DOM functions.

Finally, let's say that template system has to:
- put values
- manage loops and sections
- delete section or condition's content when (...?....)****

**** Should I delete data from PHP? I think - no - I should add data
and the library should decide whether delete some blocks.

What are your opinions?
I paused creating the CMS because of problems with choosing a good
method of creating templates.

Re: Template systems - which method?

am 11.10.2007 00:50:43 von Sascha Tayefeh

Hi WebCM,

not quite sure if I got you right, but in case you are asking for
html-templates try Smarty at http://smarty.php.net/

I have incorporated the engine into one of my projects and it works
great as far as both, usability and performance is concerned.

Sincerly

Sascha Tayefeh