472,102 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

Template systems - which method?

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

+ 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**

+ 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}
- 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 <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>&raquo; <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
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.

Oct 4 '07 #1
1 1703

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.


Sascha Tayefeh

Oct 10 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Dave Rahardja | last post: by
8 posts views Thread by Agent Mulder | last post: by
1 post views Thread by Greg Phillips | last post: by
1 post views Thread by Adam Dziendziel | last post: by
17 posts views Thread by allen.fowler | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.