473,412 Members | 2,142 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,412 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 1677
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.