Re: better way to mix html and php code?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2005-11-16 at 16:17, Miles Thompson wrote:
> At 05:04 PM 11/16/2005, Brent Baisley wrote:
> >You should separate HTML and PHP code into separate files to make it
> >easily maintainable. Ideally, someone who knows HTML without any
> >knowledge of PHP would be able to change the layout of the web page
> >without breaking anything.
> >There are a bunch of examples of how to do this, usually falling
> >under the "MVC Design Pattern" title. That's Model, View, Controller.
> >
> >I use a simple substitution system to embed "tags" that represent
> >data into my HTML files.
> >
> >The html file would look something like:
> ><table>
> ><tr><td>First Name</td>
> ><td>{:FirstName:}</td>
> ><tr><td>Last Name</td>
> ><td>{:LastName:}</td>
> ></table>
> >
> >The php file would be something like:
> >$tpl    = file_get_contents('htmlfile.htm');
> >//Assign Data to tags
> >$data['{:FirstName:}']    = 'Brent';
> >$data['{:LastName:}']    = 'Baisley';
> >//Get Tags to search on
> >$tags    = array_keys($data);
> >
> >//Populate html template with data
> >$content    = str_replace($tags, $data, $tpl);
> >echo $tpl;
> >
> >
> >That's an extremely simplified templating system and an over
> >simplified example. But it shows how you can easily completely
> >separate html from php, presentation from logic. I find it far easier
> >to work on than any of your three examples. Most importantly, it
> >allows more talented interface designer design your interface, while
> >you focus on the php and logic.
> >
> <a lot of stuff snipped>
> 
> This
> 
> ><td>{:FirstName:}</td>
> is really so different from
> 
> <td> <?php echo $FirstName ?> </td>
> 
> Why learn a templating language on top of PHP? That's one of its reasons 
> for being.

Because templating generally enforces better separation of business
logic from display logic. Because templating usually offers a less
esoteric way of working with the data (although as we all know, not
always). Because templates can allow the pre-computing of content such
that overhead can be reduced for all subsequent retrievals (and yes I
mean true savings without using a cache though mileage differs from one
system to the next). Because template tags are often shorter and
clearer. because template tags can resemble HTML, with which designers
are already familiar. Because template tags can allow for arbitrary
ordering of parameters with arbitrary parameters being optional without
the need to use an array. Because...

Anyways you suggest learning a templating language on top of PHP which
presumes the designer knows PHP in the first place. In which case if the
designer does not, a tag based system is what they already know from
which logically follows... why learn a PHP system on top of XML (of
which HTML is a subset)?

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux