Re: [PHP3] template engine example document

[email protected] (Andrei Zmievski) Sat, 25 Mar 2000 10:36:38 -0600
Newsgroups php.template
Message-ID <[email protected]>
> Not at all. There is no limit to how many HTML pages can call the same
> logic block. If the logic _features_ change, then in both of our
> methods, the programmers have to rework the pages. I'll give you an
> example: The server- wide credit card validation logic is one, and only
> one, file. It never has to be duplicated, never seen by the website
> designers. The most a designer has to do is add an hidden form variable,
> or build an HREF on a page, (both are things they're fairly
> knowledgeable about) and on the next page, know the syntax for an
> include, and decide where to put the result. So adding dynamic content
> means they need to know all of *two* statements.

> This would mean that my designers do, indeed, have to know the following
> (and they do):
> 
> Logic:
> <? include "generic_logic.inc" ?>
> 
> Presentation:
> <? echo $var ?>
> 
> So don't build different code for each web page! That doesn't require a
> new syntax, that requires building generalized logic. We are rapidly
> spiralling from the newish template debate into the old monolithic vs.
> OO debate... and your code is basically _an_ OO set of generalized
> logic, which, for some reason, you are passing using an new syntax.

Hi, Ron.

Believe me, there is nothing I'd like more than to make life easy for
both programmers and designers (let's not go into exact definition of
whta designer is for the purposes of this discussion).

Knowing 'include' and 'echo' does indeed give the designer the basic
power to create templates that are fairly functional, I suppose. From
our experience, however, we have run into several situations where just
echoing variables just might not suffice. Let's go through a couple.

1. Suppose we have a template that prints out search results. This means
that there is a portion of the template that needs to be repeated for
every search result with different values being substituted. How do you
handle that situation from your experience? Do you write a loop in a
.inc file and then include it in the template?

2. Maybe we want to print the phrase at the end of search results saying
how many there were, e.g. "There was one hit", or "There were 5 hits".
Obviously, this needs to be controlled somehow. Do you again put the
logic in .inc file and include it?

These are not contrived situations, by any means, we encounter them time
after time. I'd like to know how other people attempt to solve these,
because Monte and I may be a bit set in our ways to see past what's
obvious to us.

A rule that we try to follow is that there should be a central script or
a collection of scripts where the main logic is concentrated. These
scripts use templates for the presentation. Then you should be able to
swap one set of templates for another one and end up with a totally
different look without touching anything in the main scripts. One
template may have navigation var vertical, another - horizontal. One may
have table rows with alternating colors, the other may not. With the
system we built, it's achievable. How do you handle it?

-Andrei
* I don't have a solution but I admire the problem. *