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
> I'd like ultimately to do something like
>
> [% CGI.popup_menu({ name => "format",
> values => ## SOMETHING
> labels => ## SOMETHING
> default => ## SOMETHING
> }) %]
>
> Thanks. I'd think something like this should go into the
> docs somewhere, for people who don't want to use the whole
> HTML::Element autogeneration stuff.
>
> Jesse Sheidlower
>
> _______________________________________________
> maypole mailing list
> maypole at lists.netthink.co.uk
> http://lists.netthink.co.uk/listinfo/maypole
--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