Re: [SMARTY-DEV] object problems

From: Date: Tue, 21 Jan 2003 16:58:17 +0000
Subject: Re: [SMARTY-DEV] object problems
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-568@lists.php.net to get a copy of this message
That's pretty much the argument. The benefit of supporting access to objects in the templates is tremendous, but it would be even better if we could accomplish this without new template syntax. The template designer has no care about the underlying data structure, so why make a different syntax for it? The closest we've come is registering objects as functions, but this has many drawbacks. It is seems almost inevitable that a new syntax would be required (php-style object syntax), unless we can figure out another way that will work. Monte On Tue, 2003-01-21 at 10:48, Dennis Gearon wrote: > I wonder in all this object talk if having objects available to the: > > DESIGNERS, HTML MONKEES, GRAPHIC DESIGNERS, et. al > > fits the goal of a template engine? Are we crossing the border between code and display > separation? > > 1/21/2003 8:04:46 AM, Monte Ohrt <monte@ispi.net> wrote: > > >It seems the idea of using foo.bar for object syntax isn't working very > >well. Since objects can be assigned at runtime, there is no way to know > >at compile time how to compile foo.bar, either as an array or as an > >object. The overhead of figuring this out at runtime isn't going to be > >worth it, so it must be compiled correctly. If we are going to support > >objects in Smarty, it is either going to have to have its own syntax, or > >we limit the use of objects by having all objects registered, meaning > >they must exist before the template is executed (or your runtime > >functions/objects register new objects on-the-fly) > > > >options: > > > >1) register all objects and methods: > > > >$smarty->register('myFoo', $my, 'foo'); > > > >{myFoo p1="blah" p2="blah"} > > > >PROS: * no new syntax, looks just like a template function call. > >CONS: * cannot have arrays of objects to loop over > > * cannot pass object as parameter to function > > * every method must be registered before hand > > * property access? > > > > > >2) support new syntax for objects: > > > >{$foo->bar($foo, "bar", $blah[0].blah, nl2br($foo))} > > > >PROS: * mimics PHP native object syntax (?) > > * can pass object as parameter to function > > * can differentiate properties from methods > >CONS: * new template syntax introduced, now we pass > > parameters two different ways > > * may lead to new syntax problems, such as passing > > objects as parameters to objects > > > > > >We could go this route: > > > >{$foo->property} > >{$foo->method() p1="p1" p2="p2"} > > > >But is that much better than > >{$foo->bar("p1","p2")} > > > >The second one could be passed as a parameter, but not the first. But > >the first one does retain the parameter passing syntax. > > > > > >Any other thoughts/ideas, please do tell. I'd really like to figure out > >a way to use objects without new syntax or new style of passing > >parameters, but I don't know if that's feasible. > > > >Monte > > > > > > > >-- > >Smarty Development Mailing List (http://smarty.php.net/) > >To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.dev (#568) next »