-my @categories=C4::Category->all;
-$template->param(
- branchloop=>(defined $branch?GetBranchesLoop($branch):GetBranchesLoop()),
- categoryloop=>\@categories,
-);
+
+my @categories;
+my $no_categories;
+my $no_add = 0;
+if(scalar(@branchloop) < 1){
+ $no_add = 1;
+ $template->param(no_branches => 1);
+}
+else {
+ $template->param(branchloop=>\@branchloop);
+}
+
+@categories=C4::Category->all;
+if(scalar(@categories) < 1){
+ $no_categories = 1;
+}
+
+if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
+ $no_add = 1;
+ $template->param(no_categories => 1);
+}
+else {
+ $template->param(categories=>\@categories);
+}
+