473,246 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

templates?

Hi,

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: {$contacts[sec1].phone}<br>
fax: {$contacts[sec1].fax}<br>
cell: {$contacts[sec1].cell}<br>
{/section}

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

Rod
Jul 17 '05 #1
6 1670
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.
Jul 17 '05 #2
> 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)?


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.

Ex:
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)

Mike
Jul 17 '05 #3
WebRod wrote:
Hi,

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.
*snip*
My question is, what is the interest to learn another language??
What is the real interest of Smarty (or other one)?
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.
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.
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.
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

Rod

Jul 17 '05 #4
"WebRod" <no****@bouygtel.fr> wrote in message
news:42*********************@news.club-internet.fr...
Hi,


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.

rush
--
http://www.templatetamer.com/
http://www.folderscavenger.com/
Jul 17 '05 #5
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.

Jul 17 '05 #6
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
<news:qo********************@comcast.com>, "Using a template system is
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.

Refer:
http://www.phpbuilder.com/annotate/m...hp3?id=1013434
http://www.phpbuilder.com/annotate/m...hp3?id=1013711
http://www.phpbuilder.com/annotate/m...hp3?id=1013461
http://www.phppatterns.com/index.php...cleview/4/1/1/
http://www.massassi.com/php/articles/template_engines/
http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
<news:c1**********@newsreader.mailgate.org>

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

Refer:
http://www.sitepoint.com/forums/show...hreadid=123769

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

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The...
5
by: Tom Alsberg | last post by:
Hi there... I'm recently trying to get a bit acquainted with XML Schemas and XSL. Now, I have a few questions about XSL stylesheets and templates: * Is there a way to "enter" a child element...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
12
by: Fabio De Francesco | last post by:
Hello. I can't understand why I can't compile the following simple code, where I think I have applied all the needed rules for templates that are declared and defined in different files (*.h and...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
2
by: jimbo_vr5 | last post by:
Hey I think i've figured out the idea behind apply-templates. But going through the tutorial on <http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply just something that i dont...
25
by: Ted | last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because they were rejected in comp.lang.c++.moderated. It behooves anyone reading them to first read the the thread of the...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
104
by: JohnQ | last post by:
Well apparently not since one can step thru template code with a debugger. But if I was willing to make the concession on debugging, templates would be strictly a precompiler thing? I have a...
7
by: Chris | last post by:
Hi All, This is a weird one but I am hoping someone can help or has some pointers, a recipe how to do the following: I have to move some code from c++ to objective-c and to do this I must...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.