]> git.decadent.org.uk Git - maypole.git/blob - templates/factory/view
0ea412e2291831ecef58891ce43c3f22bd8ac0c2
[maypole.git] / templates / factory / view
1 [%#
2
3 =for doc
4
5 The C<view> template takes some objects (usually just one) from
6 C<objects> and displays the object's properties in a table. 
7
8 =cut
9
10 %#]
11 [% PROCESS macros %]
12 [% INCLUDE header %]
13
14 [% FOR item = objects %]
15 <h2> [% item.name %]</h2>
16
17 [% INCLUDE navbar %]
18
19 <TABLE class="view">
20     <TR><TD class="field">Name</TD><TD> [% item.name %] </TD></TR>
21 [% 
22     FOR col = classmetadata.columns.list;
23     NEXT IF col == "id" OR col == "name";
24     NEXT UNLESS item.$col;
25 %]
26
27 [%# 
28
29 =for doc
30
31 It gets the displayable form of a column's name from the hash returned
32 from the C<column_names> method:
33
34 %#]
35
36     <TR>
37     <TD class="field"> [% classmetadata.colnames.$col; %] </TD>
38     <TD> [%
39
40 #=cut
41
42     IF col == "url";  # Possibly too much magic.
43                 "<A HREF="; item.url; "> "; item.url; "</A>";
44     ELSE;
45
46 #=for doc
47
48 #One interesting macro used in this template is C<maybe_link_view>:
49
50         maybe_link_view(item.$col); 
51 %]
52
53 [%#
54
55 This tests whether or not the returned value is an object, and if so,
56 creates a link to a page viewing that object; if not, it just displays
57 the text as normal. The object is linked using its stringified name;
58 by default this calls the C<name> method, or returns the object's ID
59 if there is no C<name> method or other stringification method defined.
60
61 =cut
62
63 #%] 
64
65 [% END; %]
66  </TD>
67 </TR>
68 [% END; %]
69 </TABLE>
70
71 [%#
72
73 =for doc
74
75 The C<view> template also displays a list of other objects related to the first
76 one via C<has_many> style relationships; this is done by calling the
77 C<related_accessors> method - see L<Model/related_accessors> - to return
78 a list of has-many accessors. Next it calls each of those accessors, and
79 displays the results in a table.
80
81 #%]
82 [%
83     view_related(item);
84
85 #=cut
86
87     button(item, "edit");
88     button(item, "delete");
89 %]
90 [% END; %]
91