Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


i want to rewrite my website to separate the php script from the HTML code.
Therefore a web designer can update the design of the website without any
knowledge in PHP.

I read a lot of information about several templates like PhpLib,
FastTemplates, Smarty etc etc.

Some do not have a specific language so you cannot do complex things.
For example it's not easy to display a table (sometimes you need to have a
specific template to display the TR HTML tags...).
, it's not easy to use a different color to display a table row according to
a parameter etc etc

Some have a specific language, like Smarty.

My question is, what is the interest to learn another language??
What is the real interest of Smarty (or other one)?

What is the difference between these 2 situations:
I explain to a webdesigner this code:
{section name=sec1 loop=$contacts}
 phone: <br>
 fax: <br>
 cell: <br>

Or I explain this:
foreach($contacts as $key=>$contact){
 phone: <? echo $contact["phone"]?><br>
 fax: <? echo $contact["fax"]?> <br>
 cell: <? echo $contact["cell"]?> <br>

So I really think it's better to have;
- a php script which set some variables
- a HTML templates which build the content of the page. It uses a lot of
HTML tags and of course some really basic php function (if, foreach, echo).

Of course the php script call the HTML template.
You only use php, you work with the same variables, you don't need to call
some specific functions (assign etc etc), you don't need to know another
language etc etc.

Am I wrong??

Is there any interest to use Smarty (or other one)??
Why do they exist??????
And maybe why do YOU use them????

Manys thanks


Re: templates?

Quoted text here. Click to load it

For me I have always considered this a loss.  Why add another language
ontop of PHP?  To me I think it is easier to have PHP just render
everything instead of having to learn more templating languages.

The only thing I use templates for currently is a custom made XML based
system.  Takes the sections of an XML document combines them and then
parses using PHP.

All variables are exported to that template so then you have a set of
like 5 variables for that page.  So therefore all the main logic is
contained in its pure PHP form and then the templates are seperated but
the variables remain the same.

each page calls index.php which checks account validity, session, and
template file to include.  Runs through the build process if there isn't
one in the cache or if there is an updated file.

now the file is build and cached, it is now included and all the
variables are extacted to that file.  Now I simply use PHP.  This saves
rendering time, also while teaching the web designer fundimental
programming. (He is only going to be working with simple items)


Re: templates?

I use Template_IT since it allows me to have no PHP code in my HTML files
and no HTML in my PHP scripts. Templates don't always make it easy to
achieve this, but they do make it possible.

Re: templates?

WebRod wrote:
Quoted text here. Click to load it

The only advantage I can see is that these things force you to separate
presentation logic from the rest of your code, as they aren't general
purpose enough to do all that php can.

Using php for templating doesn't require all that much restraint imo
(you know things will get messy really fast if you do things the ugly
way), so I'd never introduce one more layer of complexity.

Quoted text here. Click to load it

Agree completely. My php projects consist of a controller/request
handler step (usually with a front controller/dispatcher in front of
that) and a display step.

The request handler usually calls out to object oriented business logic
which builds some kind of data model, and then include() the proper
template (which may of course include other templates again, but no
other php code).
For very simple stuff I sometimes drop the oo stuff and manage with just
request handler and template.

Quoted text here. Click to load it

Re: templates?

I've heard that said often enough: "separate out of the code from the
HTML so the web designer can work on it." In my experience it has never
worked out that way. Ususally the designer just hand me a Photoshop
file and I have to code the HTML myself.

I suspect that that's the norm rather than the exception. Designers
like to concentrate on the design, not having to think about the
technical stuff. Programmers are usually more able to actually
implement a design, especially when client-side scripting is involved.

Re: templates?

Quoted text here. Click to load it

Now I see that you have posted separately to alt.php i comp.lang.php. To
make it short, there are template systems that do not have their own
separate language, yet they can do complicated things, whil offering
separation of html and php.

http://www.templatetamer.com /
http://www.folderscavenger.com /

[FAQ] Templates (Was Re: templates?)

Q: What is "template"?
A: It would usually mean the semi-pseudo-language on the top of PHP
that uses PHP. That means, it's a language/parser written in PHP (in
PHP world). Most of the template languages are markup-based.

Q: Why using templates?
A: The original purpose is to separate PHP code from HTML. But, the
idea is flawed as it wouldn't be possible at all. Some template engines
later claimed of separating business logic from presentation logic--but
not separation of PHP code from HTML (eg, Smarty). And this is highly
disputed--many PHP saints don't agree with templating concepts and they
use PHP. Interestingly, PHP is also a template engine.

   To quote reader Chung Leong in
a little like going back to using PHP 1--you get a far less powerful,
less flexible system to work with". And it remains one of the
controversial topic in PHP and recently there seems to be a declination
in the advocacy of template engines.

  http://www.phppatterns.com/index.php/article/articleview/4/1/1 /
  http://www.massassi.com/php/articles/template_engines /

Q: How many template systems are available?
A: Lot--about or over 100.


Q: What is the widely used template system in PHP?
A: PHP. PHP itself is a template system.

Site Timeline