Re: Play nice! Re: Savant/Flexy/Foo template engines
| From: | Paul M Jones | Date: | Thu, 10 Jun 2004 19:01:53 +0000 |
| Subject: | Re: Play nice! Re: Savant/Flexy/Foo template engines | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-30416@lists.php.net to get a copy of this message | ||
And now, the point-by-point. :-)
Why?* Data assigned to the template is split into two properties, one for variables ($_vars) and one for references ($_refs). This is because they must be extracted differently: extract() only honors references back to the object property, not all the way back to the business logic. To the developer, it should "look like" there is only one storage space for both vars and refs. More on this later, when we see the setData, setDataByRef, clearData, and toString methods.It took me a while to realize the best implementation of these, they are 'data' of different types. (the direct assignment of which should really be done by outputData or outputWithData.)
- The docs in flexy explicitly explain why this method of operation is bad in principle, however, it is something that is provided if you dont agree with those principles....I must have missed that in the docs; can you point us to it?
The assignment code should reside in a datamanager (see the loading code in the example)Most if not all template systems need some sort of assignment; even those using a "pull" model still need to know where to pull from, so you need to assign the DataSource object to the template. Even at that, some folks like assigning by object rather than by array, and sometimes it's nice to assign single values by themselves. So, I'm not sure why it "should" reside in a datamanager factory, it seems to me the general problem is solved by the setData() method in the baseline class. Where have I gone wrong?
I'm not sure it's not justified. The same template system may be capable of generating both PDF and XHTML; the getMimeType() method has to know what to return. Is there some way for getMimeType() to know on its own?* There is a property for the MIME type, $_mime. Not sure if it's really needed, it gets set in openTemplate().nope - cant see any justifaction for this..
I remember trying that in early versions of Savant, and it gave me trouble with output filters. At the time, I found it more straightforward to generate a string, filter it, and then echo as needed. Let me see if I can work out your way.* There is a property for the output generated by toString(), $_output, so that it may be stored properly within toString() without possibly overwriting a reference. Better reference-checking may obviate this.the toString/output is warped? - why use output buffering at all for output() = in terms of calling it via toString, toString, should really be a output buffered wrapper around output()...
Cool, we can trade! You copy and paste the code from mine -- it's probably fewer lines, not that that matters. ;-)CODE NOTES: * The openTemplate() method seems the logical place to extend pre-filter, compile, and post-filter operations (Flexy), as well as multiple path locations (Savant).copy and past the code from my example - it's all done (although needs alot of tidying up..)
As long as the method setsYou mean the scanning of template_dir? Yes, nice, it looks familiar. ;-) I'll add something like it to the "minimalist" version, but it'll probably be outside the Jausions interface definition.$this->_tpl (the source reference) to an include()-able stream or file, extended methods should be able to handle any kind of source, whether object, stream, text, or file.the files array in the example I showed allows you to store a variety of file information, which may be usefull for different backends..
They do, in fact. Assign one object by name, and you can use it as you say above. For example:* clearData() extends the Jausions interface somewhat by allowing you to clear all values, one value by name, or a series of values listed in an array. Note that it clears both refs and vars; we want the interface to "look like" one storage unit to developers. * toString() extracts vars and refs into the local namespace differently. This bears some explanation. Let's say there is only one property ($_data) that would store all assigned data, whether by value or by reference. If we then extract($this->_data), the references extracted only go back to $_data, not back to the script that set the reference in the first place; thus, if the assigned reference changes in the calling script after it is assigned, it will not be honored within the template. As such, we must have different extraction methods for vars and refs; thus, the two separate properties, and the extra code to make it "look like" (to the developer) that there is a single storage location within the template.Flexy was specificly designed to avoid this nightmare, (eg. the overhead of extract..) - while it is necessary for the Assign API / Savant current operation, Savant templates could be more effecient having the option to use <? echo $t->somevar; ?> rather than the extract / global vars..
$Savant->assign('t', $my_object);
... then fetch() extracts that one object, and in the template, you can call <?php echo $t->somevar ?>. You can do it by reference, too, if you like.
I think that's exactly what they are. Is that bad? How else is one to implement an output filter? Yes, streams allow you to register filtering functions, but not everybody knows streams that well (I sure don't :-).* An extended toString() seems the logical place for output filters to be applied.I'm still not convinced that output filters are anything more that preg_replaces on the output to toString.. -
Yeah, me too. -- Paul M. Jones Savant: the simple alternative to Smarty for PHP. http://phpsavant.com/ DB_Table: build RDBMS tables and XHTML forms in one PHP class. http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table Yawiki: your collaborative online documentation system. http://yawiki.com/ Yawp: a single-file foundation for PHP applications. http://phpyawp.com/* toFile() is copied directly from the Jausions code, not sure it fits well here.I think it's pretty clear that that is a pretty redundant bit of code.