Re: templates with php
| From: | Andy Warwick | Date: | Mon, 31 Jul 2000 22:16:20 +0000 |
| Subject: | Re: templates with php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9295@lists.php.net to get a copy of this message | ||
A very interesting thread, and for a newbie at php like me one that is
certainly helping stretch my understanding.
As I see it the advantage of a template system is to split programmers/code
and designers/html. As someone who straddles both camps by necessity (ie I'm
the only one here :) I find it useful to split them simply for sanity and
concentration on the task in hand.
on 31/7/00 7:39 pm, Rasmus Lerdorf at rasmus@php.net wrote:
>>> My personal approach to this is to use an auto_prepend_file directive
>>> that tells PHP to automatically include a PHP script. Then in that I
>>> create the various functions and my "template" files are simple PHP files
>>> that simply call the functions. ie. <?title()?> <?price()?>
>>> <?description()?>
>
> All such directives can be set on a per-file, per-directory, and a number
> of other ways by putting them in the appropriate place in your
> httpd.conf/.htaccess file.
>
> -Rasmus
What I don't fully understand is how the code in the example above works in
practice, and where in the process the aimed-for split occurs. If the
designer has to ask the programmer to alter the .htaccess file every time he
want a different file to be auto-prepended how have we achieved the
separation of code and design?
To me, a programmer writes the logic, gets it working, then tells the
designer that he should design a particular page called 'foobar.tpl' around
the output, should leave a hole for {placeholder}, {placeholder2}, etc., and
that it should live in a certain directory, etc. This file is plain
HTML/XML, etc, and is designed to 'pretty up' the final output and nothing
more. At least that's how I separate my tasks when doing both.
on 31/7/00 8:38 pm, Rasmus Lerdorf at rasmus@php.net wrote:
> Well, you would need to restructure it a little bit and pass in your loop
> string.
I'm sorry, and maybe it's my lack of experience, but I have no idea what
this even means; "pass in your loop string" sounds like an arcane
incantation. Perhaps an example of what you mean? Thanks.
he also wrote:
> Or have functions like, <?sql_table('product_name','price')?>
> which would connect to your database, pull out the result and display a
> table of the product_name and price columns.
And at what point/how does the designer get to format that output. If the
function merely returns a finished table surely we again fail to split logic
and presentation?
on 31/7/00 10:14 pm, Monte Ohrt at monte@ispi.net wrote:
> That is why the php template engine project was born many
> months ago. You can check it out here:
>
> http://toye.php.net/~andrei/tpl-engine.html
>
> although it has made little progress lately because of the uproar it
> made regarding such a new "template syntax" for PHP, which is something
> everyone has their own opinion on.
Having read this document, I for one would love to see this approach taken,
as long as it could cope with xHTML/XML.
Maybe if I had Rasmus's in-depth knowledge of php I could comprehend his
approach, but I'm afraid I can't without a few more concrete examples.
on 31/7/00 8:38 pm, Rasmus Lerdorf at rasmus@php.net wrote:
> 6 years ago I needed a templating system myself. One that was very
> flexible, would play nice with HTML authoring tools since content types
> love to use stuff like FrontPage and DreamWeaver, and once that could
> easily be extended. 6 years later this templating system has matured a
> lot. It is called PHP. You are starting down the same path.
If you have a designer who is familiar with php, I can see the logic of what
Rasmus is saying here; as I understand it, he implies that the php document
becomes the template and you separate the code and presentation within it
using included files and functions, etc. That is subtly different to having
one file with logic and another one with presentation.
Rasmus, your template sytsem certainly has matured, into the best
server-side scripting language I have used (actually make that the best
scripting language I have used period.) What it isn't any more - at least to
me - is a template system. Perhaps we need something like the PHP Template
Engine to give us that back?
Regards
--
Andy Warwick andy.w@creed.co.uk