By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

to template or not

P: n/a
Hi,
i'm developing a website that will have an huge amount of visitors a day -->
it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.

What do you think about?
What will be your action if you'll be me?
Thanks in advance,
A.
Jul 17 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Hi Andrea,
i'd suggest you go for it! use those templates.
I'm working for a broadcasting company, we are serving upto 6.000.000 pages
per month without big performance problems
We are using the template class of phplib, which is great.

Cheers

Niels

"Andrea A" <no****@nospam.com> wrote in message
news:c1**********@newsreader.mailgate.org...
Hi,
i'm developing a website that will have an huge amount of visitors a day --> it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.

What do you think about?
What will be your action if you'll be me?
Thanks in advance,
A.

Jul 17 '05 #2

P: n/a
thanks for your answer.
Can you also tell me the hardware you use for serving this amount of pages?

thanks a lot,
a.
Hi Andrea,
i'd suggest you go for it! use those templates.
I'm working for a broadcasting company, we are serving upto 6.000.000 pages per month without big performance problems
We are using the template class of phplib, which is great.

Jul 17 '05 #3

P: n/a
Andrea A wrote:
Hi,
i'm developing a website that will have an huge amount of visitors a day -->
it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.

What do you think about?
What will be your action if you'll be me?


You can and should use Smarty. Smarty can create html cache of every
page and server it like it is HTML. That way you wouldn't overload your
server.

http://smarty.php.net/
Jul 17 '05 #4

P: n/a
pIV dual 2,4Ghz 1Gig Mem frontend
pIII dual 1,3Ghz 800Gig Mem backend

Cheers

Niels
"Andrea A" <no****@nospam.com> wrote in message
news:c1**********@newsreader.mailgate.org...
thanks for your answer.
Can you also tell me the hardware you use for serving this amount of pages?
thanks a lot,
a.
Hi Andrea,
i'd suggest you go for it! use those templates.
I'm working for a broadcasting company, we are serving upto 6.000.000

pages
per month without big performance problems
We are using the template class of phplib, which is great.


Jul 17 '05 #5

P: n/a
"Andrea A" <no****@nospam.com> wrote in message
news:c1**********@newsreader.mailgate.org...
Hi,
i'm developing a website that will have an huge amount of visitors a day --> it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.

What do you think about?
What will be your action if you'll be me?


I would obviously go with templates. Usually performace probelms are
somewhere else (like db), but I would suggest that you take in consideration
some of the template systems which have support for cacheing.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #6

P: n/a
"Andrea A" <no****@nospam.com> wrote in message news:<c1**********@newsreader.mailgate.org>...
Hi,
i'm developing a website that will have an huge amount of visitors a day -->
it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.

What do you think about?
What will be your action if you'll be me?


In reality, templating is good; but not all template engines. In
the company I'm working for, we're trying to set our own lightweight
framework. We're researching for past few weeks on template systems.
In short, you cannot simply separate code and logic---if you can
separate it, you can simply do it in PHP itself ('cos PHP itself is a
template engine; many people forget that often). Unfortuantely many
people believe that the template markup like {SOME_VARIABLE} is not a
_code_---infact they're; there is indeed no difference between {foo}
and <?=$foo?>.

These links may be helpful to further dig on the subject:

1. http://www.phpbuilder.com/annotate/m...hp3?id=1013434
2. http://www.phpbuilder.com/annotate/m...hp3?id=1013711
3. http://www.phpbuilder.com/annotate/m...hp3?id=1013461
4. http://www.phppatterns.com/index.php...cleview/4/1/1/
5. http://www.massassi.com/php/articles/template_engines/
6. http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7

P: n/a
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
"Andrea A" <no****@nospam.com> wrote in message news:<c1**********@newsreader.mailgate.org>... In reality, templating is good; but not all template engines. In
the company I'm working for, we're trying to set our own lightweight
framework. We're researching for past few weeks on template systems.
In short, you cannot simply separate code and logic---if you can
separate it, you can simply do it in PHP itself ('cos PHP itself is a
template engine; many people forget that often). Unfortuantely many
people believe that the template markup like {SOME_VARIABLE} is not a
_code_---infact they're; there is indeed no difference between {foo}
and <?=$foo?>.


Well, yes, in extremely extended definition you can say that both are code,
in the same way you can also say that html is code. Heck you can even say
that this message is code since it is coded in ASCII. What people reffer to
is the separation of programming code from the markup. One type of languages
is called markup languages, and another is called programming languages, and
for reason. The difference is that html and {SOMEVAR} is markup code wich
defines static properties, while <? php code is used to model dymanic
propertiers using if's loops, etc. And those two can be seprated, and should
imho.

There are very simple tests to see if template system separates programming
code from the html well. If you can not change behaviour of your app without
editing the files that contain html, than they are not sparated well. If you
can not change the some parts of html template without editing the file that
contains programming constructs like if's, loops etc, they are not separated
well.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #8

P: n/a
Andrea A wrote:
Hi,
i'm developing a website that will have an huge amount of visitors a day -->
it will be a contest with 100.000$ of prize.
I'm concerning about using a template class (and which one do you suggest)
or developing an optimized set of pages without using class nor PEAR
package.


Personally I avoid template libraries and rely on php itself. You can
reduce your actual pages to templates by following this process:

Write function or class libraries to encapsulate your business logic.
These should be placed outside the document root for security (if php
gets turned off no-one can download the source).

Put most of your control logic at the top of your webpage.

Use as little php inside <html></html> as possible. Simple variable
inserts and loops are fine. This way you don't need to learn another
language (the templating language) and can rely on php.

The only time this falls apart is when you need language translations.
We do this quite happily though. If the php code in the page is simple
enough you can get pages translated entire and use mod_rewrite or
Apache's own language handling to servie the right ones.

NOTE: we have some bits of our site written on Smarty and I have to
scratch my head a lot when I try and modify them. Also sometimes I want
to do things that Smarty just can't handle. I'm much happier in pure php.

....... so anyway so on to the religious flamewar
Jul 17 '05 #9

P: n/a
"rush" <pi**@rush.avalon.hr> wrote in message news:<c1**********@ls219.htnet.hr>...
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
"Andrea A" <no****@nospam.com> wrote in message news:<c1**********@newsreader.mailgate.org>...
In reality, templating is good; but not all template engines. In
the company I'm working for, we're trying to set our own lightweight
framework. We're researching for past few weeks on template systems.
In short, you cannot simply separate code and logic---if you can
separate it, you can simply do it in PHP itself ('cos PHP itself is a
template engine; many people forget that often). Unfortuantely many
people believe that the template markup like {SOME_VARIABLE} is not a
_code_---infact they're; there is indeed no difference between {foo}
and <?=$foo?>.


Well, yes, in extremely extended definition you can say that both are code,
in the same way you can also say that html is code. Heck you can even say
that this message is code since it is coded in ASCII.


Well, it sounds that you didn't try to understand what I said or
you didn't read the link that I provided.
What people reffer to
is the separation of programming code from the markup.
So...is that your defintion too? Some template engines claim
separation of dynamic code from static code---for which they just use
another markup (instead of <?=$foo?>) like {foo} or [foo] or
<!--foo--> etc. In all cases, it is merely a *substitution* of PHP's
template system with another one. Some template engines like Smarty
claims separation of business logic from presentation logic---not
separation of code; if you have tried Smarty you might be knowing
that.

All template engines use pull or push logic. So, the intution is
why not use PHP which is also a template system? It seems you claim
using <?=$foo?> in PHP developed web application is bad; but if we use
{foo} it is ok. So, it sounds that we may use ASP code as a markup in
PHP and vice-versa---and this argument is completely silly, IMHO.

One type of languages
is called markup languages, and another is called programming languages, and
for reason. The difference is that html and {SOMEVAR} is markup code wich
defines static properties, while <? php code is used to model dymanic
propertiers using if's loops, etc. And those two can be seprated, and should
imho.
It sounds that you haven't gone through Harry's
AwesomeTemplateEngine.
There are very simple tests to see if template system separates programming
code from the html well. If you can not change behaviour of your app without
editing the files that contain html, than they are not sparated well. If you
can not change the some parts of html template without editing the file that
contains programming constructs like if's, loops etc, they are not separated
well.


PHP itself is a template engine. Templating can be done with
anything--even with PHP, which is fast & easy than other weird
template markups.

--
/\
/ \\ <http://www.homeless-international.org>
/ [] \\\ Email: rrjanbiah-at-Y!com
Jul 17 '05 #10

P: n/a
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab*************************@posting.google.co m...
Well, it sounds that you didn't try to understand what I said or
you didn't read the link that I provided.
I have read those links, and tried to understand your point. Please let me
assure you that I can understand that other people have different opinions
and preferences, but in the same way I like to have mine (and other people
who have views similar to mine).
What people reffer to
is the separation of programming code from the markup.


So...is that your defintion too? Some template engines claim
separation of dynamic code from static code---for which they just use
another markup (instead of <?=$foo?>) like {foo} or [foo] or
<!--foo--> etc. In all cases, it is merely a *substitution* of PHP's
template system with another one. Some template engines like Smarty
claims separation of business logic from presentation logic---not
separation of code; if you have tried Smarty you might be knowing
that.

All template engines use pull or push logic. So, the intution is
why not use PHP which is also a template system? It seems you claim
using <?=$foo?> in PHP developed web application is bad; but if we use
{foo} it is ok. So, it sounds that we may use ASP code as a markup in
PHP and vice-versa---and this argument is completely silly, IMHO.


I have tried Smarty, and I know how it works. For my taste, template system
should separate markup from the progrmaming code, and bussines logic should
be separated from presentation by usage of MVC or some other framework.

Using <?=$foo?> is pretty similar to {FOO}, but when you start to have
conditional pieces and loops, the things start to differ pretty radically.

I do not mind if someone prefers to intersparse php code along html, it's
their taste, and their choice. But in the same time, it would feel very
un-natural for me to do it that way. Again, who wants to have code inside
html I am fine with that, but just do not tell me this is the
_only_proper_way, and that it can not be done other way.
PHP itself is a template engine. Templating can be done with
anything--even with PHP, which is fast & easy than other weird
template markups.


Yap, you can say that it is. Only for my own use I find it to be a rather
nice and usable language/library and a less than perfect template system,
because it poorely separates code from the markup.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #11

P: n/a
"rush" <pi**@rush.avalon.hr> wrote in message news:<c1**********@ls219.htnet.hr>...
<snip>
I have tried Smarty, and I know how it works. For my taste, template system
should separate markup from the progrmaming code, and bussines logic should
be separated from presentation by usage of MVC or some other framework.

Using <?=$foo?> is pretty similar to {FOO}, but when you start to have
conditional pieces and loops, the things start to differ pretty radically.
In this case, if you handle <?=$foo?> as the way you would handle
{foo} (ie, static), then the problem solved.

If you don't like the looping or conditioning inside the template,
you can just populate the list/content in the variable like
$foo_static_list and can just use it in the template. So, my point is
why making our own template engines to *just* to avoid looping &
conditioning---it can be done with PHP itself.

I do not mind if someone prefers to intersparse php code along html, it's
their taste, and their choice. But in the same time, it would feel very
un-natural for me to do it that way.
I don't mean adding conditioning & looping logic inside the
templates. I just say: why not use PHP's own markup instead of
inventing our own template markups, parser,.. And even I don't find
anything wrong with adding looping & conditioning inside the
templates--as long as presentation logic and business logic are
separated--Smarty's definition.
Again, who wants to have code inside
html I am fine with that, but just do not tell me this is the
_only_proper_way, and that it can not be done other way.
PHP itself is a template engine. Templating can be done with
anything--even with PHP, which is fast & easy than other weird
template markups.


Yap, you can say that it is. Only for my own use I find it to be a rather
nice and usable language/library and a less than perfect template system,
because it poorely separates code from the markup.


Most of the Designers use DW (at least here in India). PHP's own
markups are DW friendly. For example,

<td><?=$var1?></td><td><?=$var2?></td>

In the above case, if the Designer wants to add some bit of
"colours", then it is easy for him to do so---'coz PHP codes will
never break up or mess up.

But, if you use other markups, it is possible that he may mess up
like:

<td>{var1}</td><td><b>{var2</b>}</td> <--note the <b> tag

Well, you may claim that we can add our own markup to DW so that it
looks different. Yes, we can invent our own markup & add it---then why
if everything is available as cool and simple?

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #12

P: n/a
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab*************************@posting.google.co m...
In this case, if you handle <?=$foo?> as the way you would handle
{foo} (ie, static), then the problem solved.

If you don't like the looping or conditioning inside the template,
you can just populate the list/content in the variable like
$foo_static_list and can just use it in the template. So, my point is
why making our own template engines to *just* to avoid looping &
conditioning---it can be done with PHP itself.
what if $foo_static_list needs to use other template, and conditions within,
and loops within condition, etc, which happens in most nicely designed
pages? What would be a clean way to populate it? Encode tha complex piece of
html as a string in php?
I don't mean adding conditioning & looping logic inside the
templates. I just say: why not use PHP's own markup instead of
inventing our own template markups, parser,.. And even I don't find
anything wrong with adding looping & conditioning inside the
templates--as long as presentation logic and business logic are
separated--Smarty's definition.
Well, if that suits you fine. I do not like code that is intemixed with
html. For me it is hard to read, hard to write, and pain to maintain in the
same file together with designer. This is the reason I do not use php's own
markup, or templates that have programming constructs. If you find that
these reasons do not bother you, (and obviously they don't) than just write
the way you are.

On top of template system I separate presentation logic from bussines logic
by MVC or something similar, not by template system.
<td>{var1}</td><td><b>{var2</b>}</td> <--note the <b> tag


If it starts happening to me I will think start thinking about it as a
problem. But what was happning to me, were the cases when designer cutted
away good pieces of php code, moved it in inproper places, or messed it up
inadverdently while changing the layout. And that is the problem I have
solved by usage of templates.

Again, I can understand that you do not prefer or do not have need to use
templates, I am fine with that. But just understand that I have a need for
them, and that they are for me powerfull and usable, and going back to not
use them would feel for me as going back into stone age.

rush
--
http://www.templatetamer.com/
Jul 17 '05 #13

P: n/a
On Wed, 25 Feb 2004 14:02:32 +0100, "rush" <pi**@rush.avalon.hr> wrote:
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab*************************@posting.google.c om...

I don't mean adding conditioning & looping logic inside the
templates. I just say: why not use PHP's own markup instead of
inventing our own template markups, parser,.. And even I don't find
anything wrong with adding looping & conditioning inside the
templates--as long as presentation logic and business logic are
separated--Smarty's definition.


Well, if that suits you fine. I do not like code that is intemixed with
html. For me it is hard to read, hard to write, and pain to maintain in the
same file together with designer. This is the reason I do not use php's own
markup, or templates that have programming constructs. If you find that
these reasons do not bother you, (and obviously they don't) than just write
the way you are.

On top of template system I separate presentation logic from bussines logic
by MVC or something similar, not by template system.
<td>{var1}</td><td><b>{var2</b>}</td> <--note the <b> tag


If it starts happening to me I will think start thinking about it as a
problem. But what was happning to me, were the cases when designer cutted
away good pieces of php code, moved it in inproper places, or messed it up
inadverdently while changing the layout. And that is the problem I have
solved by usage of templates.


Just trying to understand this.

Suppose you have a page which has to display a variable-length list of
products. If the length is zero, it puts up a paragraph along the lines
of "no products currently available in this category".

How do you do that in a template which includes no code?

--
Stephen Poley
Jul 17 '05 #14

P: n/a
"Stephen Poley" <sb******************@xs4all.nl> wrote in message
news:oj********************************@4ax.com...
Suppose you have a page which has to display a variable-length list of
products. If the length is zero, it puts up a paragraph along the lines
of "no products currently available in this category".

How do you do that in a template which includes no code?


Hi, here is outline how would you do it with TT, on the web site there is a
number of examples starting from simpler to more complex ones, and if you
need more please mail me.

First here is html template file

html/prodlist.html:
<html>
<body>
<h1>Phone MegaStore Special</h1>

<!--NAME:ONEPRODUCT-->
Product Name:{PRODNAME} price: {PRODPRICE}<br><hr>
<!--END:ONEPRODUCT-->

<!--NAME:NOPRODUCTS-->
Sorry no products found ...
<!--END:NOPRODUCTS-->

</body>
</html>

The ONEPRODUCT template contains html for each product row, and NOPRODUCTS
contains html for the case where you have no products at all. Now let's see
the php logic file that drives it:

logic/prodlist.logic.php:

<?PHP

class prodlist_Page extends TemplateTamer_Page {

function getData() {
$products = $this->getProducts(); // let's suppose that getProducts
gets all products in array
if (size($products) > 0) {
foreach($products as $productName=>$productPrice) {
$productList[] = array(
'PRODNAME' => $productName,
'PRODPRICE' => $productPrice
);
}
return array( 'ONEPRODUCT' => new RepeatTemplate($productList) );
} else
return array( 'NOPRODUCTS' => array( ) );
}

function getProducts() {
// modify this fuction to get the actual product list ...
return array(
'Phones that work' => 100,
'Phones that do not work' = 1
);
}

}
?>

rush
--
http://www.templatetamer.com/
Jul 17 '05 #15

P: n/a

On Thu, 26 Feb 2004 18:27:21 +0100, "rush" <pi**@rush.avalon.hr> wrote:
"Stephen Poley" <sb******************@xs4all.nl> wrote in message
news:oj********************************@4ax.com.. .
Suppose you have a page which has to display a variable-length list of
products. If the length is zero, it puts up a paragraph along the lines
of "no products currently available in this category".

How do you do that in a template which includes no code?
html/prodlist.html:
<html>
<body>
<h1>Phone MegaStore Special</h1>

<!--NAME:ONEPRODUCT-->
Product Name:{PRODNAME} price: {PRODPRICE}<br><hr>
<!--END:ONEPRODUCT-->

<!--NAME:NOPRODUCTS-->
Sorry no products found ...
<!--END:NOPRODUCTS-->

OK, I get the general idea, thanks.

I think on the whole I'd just as soon as have something like:

<?php if ($products==0): ?>
Sorry ...
<?php endif ?>

but I can see some people might just prefer your version.

--
Stephen Poley
Jul 17 '05 #16

P: n/a
"rush" <pi**@rush.avalon.hr> wrote in message news:<c1**********@ls219.htnet.hr>...
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab*************************@posting.google.co m...
In this case, if you handle <?=$foo?> as the way you would handle
{foo} (ie, static), then the problem solved.

If you don't like the looping or conditioning inside the template,
you can just populate the list/content in the variable like
$foo_static_list and can just use it in the template. So, my point is
why making our own template engines to *just* to avoid looping &
conditioning---it can be done with PHP itself.
what if $foo_static_list needs to use other template, and conditions within,
and loops within condition, etc, which happens in most nicely designed
pages? What would be a clean way to populate it? Encode tha complex piece of
html as a string in php?


I didn't say that it's the only way. What I said was, if you prefer
the markup to be static, you can even do it in PHP--no need to go for
another markup, another parser, etc. That was my point.
I don't mean adding conditioning & looping logic inside the
templates. I just say: why not use PHP's own markup instead of
inventing our own template markups, parser,.. And even I don't find
anything wrong with adding looping & conditioning inside the
templates--as long as presentation logic and business logic are
separated--Smarty's definition.


Well, if that suits you fine. I do not like code that is intemixed with
html. For me it is hard to read, hard to write, and pain to maintain in the
same file together with designer. This is the reason I do not use php's own
markup, or templates that have programming constructs. If you find that
these reasons do not bother you, (and obviously they don't) than just write
the way you are.

On top of template system I separate presentation logic from bussines logic
by MVC or something similar, not by template system.


Yes, I understand you may need to go for another layer to manage
the presentation & logic. But, our aim is to get the simple
lightweight framework--which I believe can be done with PHP itself,
but with some isolation of logic. And I understand, YMMV.
<td>{var1}</td><td><b>{var2</b>}</td> <--note the <b> tag


If it starts happening to me I will think start thinking about it as a
problem. But what was happning to me, were the cases when designer cutted
away good pieces of php code, moved it in inproper places, or messed it up
inadverdently while changing the layout. And that is the problem I have
solved by usage of templates.


I think, your designer use some other tools. It never happend to us
'coz we used to separate header & footer--the most touchup work will
be on a small template (PHP+HTML) code.
Again, I can understand that you do not prefer or do not have need to use
templates, I am fine with that. But just understand that I have a need for
them, and that they are for me powerfull and usable, and going back to not
use them would feel for me as going back into stone age.


I too use a kind of template system. Sometimes ago, I posted my
script here <http://groups.google.com/groups?selm=abc4d8b8.0402130547.2f09d2af%40posting .google.com>
In usual developement, I hardly (or never) use echo and so it is easy
for the designer to touch it easily. At a maximum, it require just 3
phase:

1. Our code-gen, generates the code (PHP & HTML)
2. Templating HTML code goes to designer to add "colours" -- hardly
happens as the code-gen will generate CSS based code.
or
1. Designer provides pure HTML template (without any template
markup)
2. Developer inserts some PHP templating like <?=$foo?>
3. Designer gets the PHP powered template and adds "colours" --
rarely happens as the first HTML template itself will be sufficient.

When we want to setup a lightweight framework, people prefer even
too simple system. And right now, we're considering:
- Henk Verhoeven's template
<http://groups.google.com/groups?selm=btv963%245se%241%40news2.tilbu1.nb.hom e.nl>
- Brian Lozier's template
<http://www.massassi.com/php/articles/template_engines/> (seems to be
nice if caching is necessary)
- or even Harry's simple AwesomeTemplateEngine
- and moreover, we have to comeup with better system (as it going
to be proprietary)

For me, if we prefer some new markup, we may go for Zope or similar
languages, instead of inventing them in PHP itself. I understand, many
people prefer to stay in PHP, but like to use other kind of
templating.

p.s: Apologies for late follow-up; I was so busy.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.