Bug 24745: OPAC news block plugin should evaluate as false if there are no items
[koha.git] / Koha / Template / Plugin / KohaNews.pm
blob713d07301a0c2b94b60c47fe9ecc3fc2451f18ba
1 package Koha::Template::Plugin::KohaNews;
3 # Copyright ByWater Solutions 2012
4 # Copyright BibLibre 2014
5 # Parts copyright Athens County Public Libraries 2019
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Modern::Perl;
24 use Template::Plugin;
25 use base qw( Template::Plugin );
27 use C4::Koha;
28 use C4::Context;
29 use C4::NewsChannels; # GetNewsToDisplay
31 sub get {
32 my ( $self, $params ) = @_;
34 my $display_location = $params->{location};
35 my $blocktitle = $params->{blocktitle};
36 my $lang = $params->{lang};
37 my $library = $params->{library} || "";
38 my $news_lang;
40 if( !$display_location ){
41 $news_lang = $lang;
42 } else {
43 $news_lang = $display_location."_".$lang;
46 my $content = &GetNewsToDisplay( $news_lang, $library );
48 if( @$content ){
49 return {
50 content => $content,
51 location => $display_location,
52 blocktitle => $blocktitle
54 } else {
55 return 0;
61 =head1 NAME
63 Koha::Template::Plugin::KohaNews - TT Plugin for displaying Koha news
65 =head1 SYNOPSIS
67 [% USE KohaNews %]
69 [% KohaNews.get() %]
71 =head1 ROUTINES
73 =head2 get
75 In a template, you can get the all categories with
76 the following TT code: [% KohaNews.get() %]
78 =head1 AUTHOR
80 Owen Leonard <oleonard@myacpl.org>
82 =cut