Home > Archive > PHP Programming > May 2005 > templates?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| WebRod 2005-05-30, 3:56 pm |
| 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
| |
| Mick Sharpe 2005-05-30, 3:56 pm |
| 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.
| |
| Mike Willbanks 2005-05-30, 3:56 pm |
| > 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
| |
|
| 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
>
>
| |
|
| "WebRod" <nomail@bouygtel.fr> wrote in message
news:429b1091$0$308$7a628cd7@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/
| |
| Chung Leong 2005-05-31, 3:58 pm |
| 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.
|
|
|
|
|