Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Template systems - which method?
October 4, 2007, 3:25 pm
rate this thread
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.
- 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
+ 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 support - everything is based on DOM**
+ you are independent of language you use in templates (e.g.
+/- only one instance optClass of template system (you can change
+/- based on template language (,
- 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 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 <input type="button" /> (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:
<a>» <span id="here" /></a>
*** I think XT idea is better for code redability. But what with
caching? Is it needed? Remember that you must load template through
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?
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.