Thread: [htmltmpl] 2 New(?) Ideas
Brought to you by:
samtregar
From: Jason P. <ja...@jo...> - 2004-12-03 20:52:26
|
While I'm thinking about this, what do you guys think about these? 1) Class::DBI Integration I'm just starting to pick up CDBI (I know, I'm late to the party ;)) and it's kind of frustrating to get the data into the template. Or it could be made easier. I'm not sure if we're talking Plugin or an update to the core, but what would be really cool is to accept CDBI objects in the 'associate' parameter: $user_record = CDBI::Subclass->retrieve( $primary_key ); $template = $self->load_tmpl( 'main.TMPL', 'die_on_bad_params' => 0, 'associate' => [ $query, $user_record ], ); Another cool tweak would be to HTML::Template such that you could do a search on the CDBI object and just pass along the results: @results = CDBI::Subclass->search( 'year' => '1980' ); $template->param( 'results' => \@results ); It could be an easy tweak to the code, where if when trying to fill out a <TMPL_VAR NAME="foo"> from the template's internal param hash or from the associated objects' param methods fail, it will try a last-ditch effort of going through associated objects' methods named after the same parameter name (i.e. foo()). These thoughts aren't that well-organized, so I hope you get the jist of what I'm aiming for. I'm mostly hoping to instigate some thoughts on how we can get CDBI better supported in cgiapp & htmltmpl. I know we could add a param() method to the CDBI subclass, but that seems kind of a pain to me. I just dug around the htmltmpl list and found this post[1] that's very similiar to what I'm trying to address. Cees (& another poster) says that he adds something to his CDBI subclass, but again, we could do better by centralizing that same code in the htmltmpl core or a plugin, so we don't have to copy/paste that code in every CDBI subclass we have (and just for one app, I have about 6). Cees also points to Template, but I don't see why we can't also have it in htmltmpl. I'm kinda stuck on htmltmpl, personally -- it's very simple and it keeps me from bleeding logic into the template layer of my applications. 2) Status Messages In an app flow like A -> B -> A, I would like to have a status message on A when B has been successfully processed, but what's the best way to do this? Stuff the message in cgiapp's param? Pass along a param to the runmode method? Then pass that to the template as a param? Cheers, Jason [1]: http://sourceforge.net/mailarchive/message.php?msg_id=8629899 |
From: David H. <da...@ho...> - 2004-12-03 20:58:19
|
On 3 Dec 2004, at 20:52, Jason Purdy wrote: > While I'm thinking about this, what do you guys think about these? Use the Template Toolkit. HTML::Template does what it does very well. Don't overload it. -- Dave Hodgkinson CTO, Rockit Factory Ltd. http://www.rockitfactory.com/ Web sites for rock bands |
From: David H. <da...@ho...> - 2004-12-03 21:44:29
|
On 3 Dec 2004, at 21:16, Jason Purdy wrote: > I'm not sure if you're just trolling me here w/ that simple response, > but I did talk about how I didn't want to use TT. I don't believe > adding support for CDBI would be overloading it, just making it easier > to use. If you're still skeptical, it could be done as an extension > or plugin such that it doesn't add any "bloat" to the core. HTML::Template's strength is its simplicity. It does a couple of things perfectly and leaves the rest to "real" code. The separation of almost everything except display is strong. Build the data structure and let H::T do the rest. The project I'm working on right now has HTML::Template, Text::Template *and* TT, each used for specific purposes. > > Jason > > David Hodgkinson wrote: >> On 3 Dec 2004, at 20:52, Jason Purdy wrote: >>> While I'm thinking about this, what do you guys think about these? >> Use the Template Toolkit. >> HTML::Template does what it does very well. Don't overload it. > > -- Dave Hodgkinson CTO, Rockit Factory Ltd. http://www.rockitfactory.com/ Web sites for rock bands |
From: Clifton R. <cli...@ti...> - 2004-12-03 22:12:49
|
On Fri, Dec 03, 2004 at 03:52:17PM -0500, Jason Purdy wrote: > While I'm thinking about this, what do you guys think about these? > > 1) Class::DBI Integration > I'm just starting to pick up CDBI (I know, I'm late to the party ;)) and > it's kind of frustrating to get the data into the template. Or it could > be made easier. I'm not sure if we're talking Plugin or an update to > the core, but what would be really cool is to accept CDBI objects in the > 'associate' parameter: This can/should happen in your code - simply create a CDBI-derived CDBI::Extended object which has a CGI/HT compatible "params" method, and pass that to associate. Hey presto! If you're wanting to create a bunch of CDBI subclasses, then you just subclass that CDBIE instead. Done. If you think this would be really useful to a lot of people then encapsulate the CDBIE neatly and publish it in CPAN. (Alternatively, you could subclass HT, but since HT already has a well-defined interface for feeding params in, which already interoperates with some Perl modules, it seems more logical to add it on the other side.) -- Clifton -- Clifton Royston -- cli...@ti... Tiki Technologies Lead Programmer/Software Architect Did you ever fly a kite in bed? Did you ever walk with ten cats on your head? Did you ever milk this kind of cow? Well we can do it. We know how. If you never did, you should. These things are fun, and fun is good. -- Dr. Seuss |
From: Sam T. <sa...@tr...> - 2004-12-04 18:30:25
|
On Fri, 3 Dec 2004, Jason Purdy wrote: > 1) Class::DBI Integration > I'm just starting to pick up CDBI (I know, I'm late to the party ;)) and it's > kind of frustrating to get the data into the template. Or it could be made > easier. I'm not sure if we're talking Plugin or an update to the core, but > what would be really cool is to accept CDBI objects in the 'associate' > parameter: > > $user_record = CDBI::Subclass->retrieve( $primary_key ); > $template = $self->load_tmpl( > 'main.TMPL', > 'die_on_bad_params' => 0, > 'associate' => [ $query, $user_record ], > ); The associate feature is a pretty brutal hack as it is. I think you'd be better off creating a sub-class of HTML::Template which supported a new option like 'class_dbi' for this functionality. You could then call param() using some pre-defined translation between Class::DBI space and HTML::Template space. > Another cool tweak would be to HTML::Template such that you could do a search > on the CDBI object and just pass along the results: > > @results = CDBI::Subclass->search( > 'year' => '1980' > ); > $template->param( 'results' => \@results ); That should also be reasonably easy to do in a sub-class. > 2) Status Messages > In an app flow like A -> B -> A, I would like to have a status message on A > when B has been successfully processed, but what's the best way to do this? > Stuff the message in cgiapp's param? Pass along a param to the runmode > method? Then pass that to the template as a param? I wrote a message about this on the CGI-App mailing-list a while back. Let's see if I can find it. Here it is: http://www.mail-archive.com/cg...@li.../msg01987.html I'm still planning to write that article... -sam |