[Catalyst] Catalyst + CDBI + TT + HTML::Element question
Luigi Iotti
catalyst at iotti.biz
Tue Nov 14 15:19:10 GMT 2006
Hi all
I'm new to Catalyst, and have a basic knowledge of Perl.
I have to maintain an app mainly built with Catalyst, Class::DBI and
Template Toolkit. The app has a template to let the user add records to a
table.
This template cycles through the tables's columns and outputs a field for
every column.
The selection fields are trated in a particular way, like this:
[% FOR column = display_columns %]
...
[%
SET field = table_class.to_field(column);
IF field.tag == 'select';
USE element_maker = Class("HTML::Element");
SET field = field.unshift_content(element_maker.new("option",
value,""));
END;
%]
<td>
[% field.as_XML; %]
...
[% END %]
Now, the values available in the selection fields are all and only the ones
found via a has_a relationship in the CDBI definition of the table. I have
to modify the app to only present and make available some of the possibile
vaules in a certain selection field, and not all the values present in the
has_a table as it is now.
I thought to put on the stash the 'selectable' values (selectable_values
array in the sample code below), and to modify the template to contain only
the selectable values, like this:
[% FOR column = display_columns %]
...
[% IF column != 'special_column' %]
[%
SET field = table_class.to_field(column);
IF field.tag == 'select';
USE element_maker = Class("HTML::Element");
SET field = field.unshift_content(element_maker.new("option",
value,""));
END;
%]
<td>
[% field.as_XML; %]
[% ELSE %]
[%
SET field = table_class.to_field(column);
SET field = field.delete_content();
FOR value = selectable_values;
SET field = field.push_content(["option",{value =>
value.id},value.desc]);
END;
%]
[% field.as_XML; %]
...
[% END %]
...
[% END %]
It works, but I'm wondering if I chose the better way to do it.
Thank you in advance
Luigi
More information about the Catalyst
mailing list