| 23 | | |
| 24 | | # This anonymous subroutine will process each row of data. It takes |
| 25 | | # as input the object associated with the current row, and an empty |
| 26 | | # hash for the row that should be populated with content from the |
| 27 | | # $obj passed to it. |
| 28 | | my $code = sub { |
| 29 | | my ($obj, $row) = @_; |
| 30 | | $row->{'column1'} = $obj->id; |
| 31 | | $row->{'column2'} = $obj->title; |
| 32 | | my $ts = $row->{created_on}; |
| 33 | | $row->{date} = relative_date($ts, time); |
| 34 | | }; |
| 35 | | |
| 36 | | # %terms is used in case you want to filter the contents of the |
| 37 | | # table in someway |
| 38 | | my %terms = ( |
| 39 | | # author_id => $app->user->id, |
| 40 | | ); |
| 41 | | |
| 42 | | # %args is used in case you want to sort or otherwise modify the |
| 43 | | # query arguments of the table |
| 44 | | my %args = ( |
| 45 | | sort => 'created_on', |
| 46 | | direction => 'descend', |
| 47 | | ); |
| 48 | | |
| 49 | | # %params is an addition hash of input parameters into the template |
| 50 | | # and can be used to hold an arbitrary set of name/value pairs that |
| 51 | | # can be displayed in your template. |
| 52 | | my %params = ( |
| 53 | | some_variable => 'You can do ANYTHING in Movable Type', |
| 54 | | ); |
| 55 | | |
| 56 | | # Fetch an instance of the current plugin using the plugin's key |
| 57 | | my $plugin = MT->component('Navigator'); |
| 58 | | |
| 59 | | # The main work horse of your handler. This will actually conduct |
| 60 | | # the query to the database for you, populate all that is necessary |
| 61 | | # for the pagination controls and more. The query is filtered and |
| 62 | | # controlled using the %terms and %args parameters. |
| 63 | | $app->listing({ |
| 64 | | type => 'page', # the ID of the object in the registry |
| 65 | | terms => \%terms, |
| 66 | | args => \%args, |
| 67 | | # listing_screen => 1, |
| 68 | | code => $code, |
| 69 | | template => $plugin->load_tmpl('view.tmpl'), |
| 70 | | params => \%params, |
| 71 | | }); |
| 72 | | |
| 73 | | |
| 74 | | |
| 75 | | # $app->build_page( 'view.tmpl', \%param ); |
| | 39 | $app->build_page( 'edit.tmpl', \%param ); |