Paul M Foster wrote:
On Mon, May 10, 2010 at 11:37:21PM -0400, Robert Cummings wrote:
Paul M Foster wrote:
<snip>
Lots of people use templating systems and particularly Smarty. Here's
the difference between a templating system and just hand-coding:
Hand coding--
<input type="text" name="flavor" size="20" value="<?php echo $flavor;
?>"/>
Templating system:
<input type="text" name="flavor" size="20" value={flavor}/>
(Okay, I'm not familiar with Smarty syntax, but in essence template
systems allow you to type less when you want PHP values to show up on
the page.)
Advantage: It *may* be easier for non-programmers to "read" the page
with templating systems. I'm not sure this is really true. They're still
liable to say, "What the heck is {flavor}?" Besides, my inclination is
to tell designers to make everything look pretty, turn the resulting
HTML over the the coders, who will then mark it up for PHP. After that,
the designers can stay away from it.
Disadvantage: You're adding another layer (and a LOT of code) just to
save yourself some typing. With straight PHP, the server reads the code,
interprets the PHP, substitutes values and shoves the page down to the
browser. With a templating system, the system must load and call the
templating engine, which must then substitute the proper values, and
then output the built page to the browser.
Your choice.
I get tired of correcting this incorrect assertion. Some templates
engines do what you describe. Not all. Some directly generate PHP source
code which is then either directly accessed via the web server or
directly included by another page. Generating PHP code from a template
engine can provide superior benefits over pure PHP since the distilling
of simple XML (or otherwise) tags can be rendered once via simple or
complex PHP processing during template compilation versus the same
processing being done on every page request. In fact some will produce
plain HTML that doesn't even require the PHP interpreter.
Okay, you're clearly more familiar with templating systems than I am. My
impression of templating systems is that the templating engine scans the
raw page, makes substitutions, and then outputs the page to the browser,
all on the fly. You're saying this isn't always the case.
Are you saying that some templating systems simply generate output,
which may then at some later time, be requested by the browser? That is,
they would function somewhat like a combination of "make" and "m4" (a
macro processor)? So a programmer would code his page, then call the
templating engine, which would output the final page to disk, so it is
now available for download? Is that the distinction you're making?
Yes :) Or some combination of this and what you described. Or this and
caching. It doesn't necessarily have to be built like an application
such as make would do. The application can lazy load the template
engine, compile the template(s) and then subsequently do an include() on
future requests. The compiled source code would run in the context of
the including function and so would be able to pull variables from this
context and so directly embedded PHP code could output these variables
as you suggest but without the template designed using explicit PHP
calls, or having to know about functions, or parameter order, etc.
Smarty is a push template engine. You push variables to the smarty
engine. You tell smarty to load the template. Smarty processes the
template by replacing tags or macros with the pushed values. Smarty is
also responsible for the caching so you kinda need to load the whole
bundle just to get the cached output. The type of template structure I'm
describing is a pull structure where the template pulls the data that
has been initialized via PHP code generated by the template engine.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php