Re: [Maypole] Access to has_a data from template?

From: Simon Flack (sf at flacks.net)
Date: Thu Sep 16 2004 - 09:23:56 BST


On Thu, 16 Sep 2004 09:14:47 +0100, Simon Flack wrote
> On Wed, 15 Sep 2004 22:38:35 -0400, Jesse Sheidlower wrote
> > I just sat down to do something I thought would be easy,
> > and found that I can't really figure out how to get it done.
> >
> > I'd like to generate my own HTML form elements from within
> > a template, without using the built-ins that use as_form
> > or as_html. To pick the simplest example, suppose I'm in
> > my "book" class, at http://mysite.com/book/add . Each
> > "book" has_a "format".
> >
> > I thought there would be a way to get right to the format
> > stuff, but there doesn't seem to be. Yet even when I start
> > with the Template::Plugin::Class stuff it doesn't seem to
> > work: if I try
> >
> > [% USE book = Class(classmetadata.name) %]
> >
> > (classmetadata.name convieniently returns MyDB::Book or
> > whatever), I still can't seem to get at the related
> > stuff: doing something like
> >
> > FOREACH format = book.format
> >
> > bombs out with
> >
> > undef error - Can't fetch data as class method at
> > /usr/local/lib/perl5/site_perl/5.8.5/Template/Plugin/Class.pm
> > line 35
>
> This is really a Class::DBI question. I think you need to query
> book->meta_info('has_a') to get the class that represents the has_a
> relationship. Something like this:
>
> [% SET format=book.meta_info('has_a', 'format').class %]
> [% FOREACH book_format=format.retrieve_all %]
>
> Of course, you may not want to do this since meta_info() is
> undocumented. There may be another way of doing this.
>
> See: http://class-dbi.com/cgi-bin/wiki/index.cgi?CdbiWishList

However you end up doing this, it might be better to abstract it into a
list_all_formats() class method on your book class.

--simonflk

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:56 GMT