diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-02-23 11:56:37 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-02-23 11:57:31 +0000 |
commit | a3b774254a987c767dae890ed076e685dff4c561 (patch) | |
tree | 5bf352d875ffcca2d251dc816f5e6326b21c93da | |
parent | a20baf15cabeaf50b6d9e5632e59cd44f18976bc (diff) |
Factor out fragment rendering, as additional template paths needs to be passed.
-rw-r--r-- | perllib/FixMyStreet/App.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 6 |
4 files changed, 25 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 21552a066..d39ae1415 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -402,6 +402,22 @@ sub finalize { delete $c->stash->{cobrand}; } +=head2 render_fragment + +If a page needs to render a template fragment internally (e.g. for an Ajax +call), use this method. + +=cut + +sub render_fragment { + my ($c, $template, $vars) = @_; + $vars ||= {}; + $vars->{additional_template_paths} = [ $c->cobrand->path_to_web_templates->stringify ] + unless $c->cobrand->is_default; + $c->view('Web')->render($c, $template, $vars); +} + + =head1 SEE ALSO L<FixMyStreet::App::Controller::Root>, L<Catalyst> diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 148a22368..ac8e0e719 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -258,12 +258,11 @@ sub ajax : Path('/ajax') { FixMyStreet::Map::map_pins( $c, $interval ); # render templates to get the html - my $on_map_list_html = - $c->view('Web') - ->render( $c, 'around/on_map_list_items.html', { on_map => $on_map } ); - - my $around_map_list_html = $c->view('Web')->render( - $c, + my $on_map_list_html = $c->render_fragment( + 'around/on_map_list_items.html', + { on_map => $on_map } + ); + my $around_map_list_html = $c->render_fragment( 'around/around_map_list_items.html', { around_map => $around_map, dist => $dist } ); diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 8f71a5c2e..3f55e4692 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -98,7 +98,7 @@ sub _crop { $image->BlobToImage($photo); my $err = $image->Resize( geometry => "90x60^" ); throw Error::Simple("resize failed: $err") if "$err"; - my $err = $image->Extent( geometry => '90x60', gravity => 'Center' ); + $err = $image->Extent( geometry => '90x60', gravity => 'Center' ); throw Error::Simple("resize failed: $err") if "$err"; my @blobs = $image->ImageToBlob(); undef $image; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ee471499c..9eefc9396 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -112,8 +112,8 @@ sub report_form_ajax : Path('ajax') : Args(0) { $c->forward('setup_categories_and_councils'); # render templates to get the html - my $category = $c->view('Web')->render( $c, 'report/new/category.html'); - my $councils_text = $c->view('Web')->render( $c, 'report/new/councils_text.html'); + my $category = $c->render_fragment( 'report/new/category.html'); + my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); my $has_open311 = keys %{ $c->stash->{category_extras} }; my $body = JSON->new->utf8(1)->encode( @@ -150,7 +150,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->stash->{report} = { category => $c->req->param('category') }; $c->stash->{category_extras} = { $c->req->param('category' ) => $c->stash->{category_extras}->{ $c->req->param('category') } }; - $category_extra= $c->view('Web')->render( $c, 'report/new/category_extras.html'); + $category_extra= $c->render_fragment( 'report/new/category_extras.html'); } my $body = JSON->new->utf8(1)->encode( |