Re: [PHP Template] Re: My template idea...

[email protected] (Manuel Hossfeld)
Newsgroups php.template
Message-ID <[email protected]>
Hi,

On Tue, Feb 15, 2000 at 04:05:15PM -0600, Andrei Zmievski wrote:
> On Tue, 15 Feb 2000, Tobias Ratschiller wrote:
> > What could be an interesting feature, though:
> > With the whole template concept, in real life you often end up assigning a
> > lot of variables or array elements to the placeholder of the same name, for
> > example:
> > tpl_assign("variable", $variable);
> > or tpl_assign() using the schema but with an array.
> > This could be shortened to a a tpl_batch_assign(), taking only the
> > placeholder name and automatically inserting the variable with the
> > corresponding name for it.
> 
> Where does this variable come from? Can you expand on this or provide
> short pseudo code?

Of course, I can't read Tobias' mind, ;-) but I think I know what he wants.
Actually, I implemented something very similar for my own template usage:

Problem:
You often have many assignments like
$tpl->assign("TITLE", $title);
$tpl->assign("BANNER", $banner);
$tpl->assign("NAVBAR", $navbar);
etc.etc...

To save some typing, and to have code that's easier to read and maintain I
wrote a little wrapper, "MetaTemplate", which shorten's this to:

$meta_tpl->doit("title banner navbar");

(On top of that, I also used it as an abstraction layer to be independent
from an individual template engine, and used it both with FastTemplate and
PHPLIB templates.)

At the heart of the "MetaTemplate" class is this code
(here the FastTemplate variant):

        function fill($values) {  // this method is called by doit()
                $vars = explode (" ", $values);
                for ($i=0; $i<count($vars); $i++) {
                        $handle = strtoupper($vars[$i]);
                        $val = $GLOBALS[$vars[$i]];
                        $this->tpl->assign($handle, $val);
                }
        }
	
And that's probably what Tobias also meant...

IMHO, it would be good to have many "automatic things" like this - user
configurable of course. Implicit bevaviour and/or sensible defaults can
really make life easier for both the designer and the coder...

CU,
Manuel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.