diff --git a/CHANGES.md b/CHANGES.md
index a22086d74bdf0dd716b9e5bc975f2d38fd5c36a9..a3e2829784059ac4d48f9dfbd26617e2496d62d1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,9 @@ moodle-theme_boost_campus
 Changes
 -------
 
+### Unreleased
+* 2020-09-01 - Fixed bug that multiple imagearea rows are displayed dependent on the amount of uploaded images.
+
 ### Release v3.8-r4
 
 * 2020-08-27 - Fixed bug in image area feature if link attribute was left empty.
diff --git a/layout/includes/imagearea.php b/layout/includes/imagearea.php
index 247897310fdb76cc3585df4ad44cd525dafa5607..7afe48b4adac85e68b74b78362fadeb535ddae1b 100755
--- a/layout/includes/imagearea.php
+++ b/layout/includes/imagearea.php
@@ -24,6 +24,7 @@
  */
 
 defined('MOODLE_INTERNAL') || die();
+global $CFG;
 require_once($CFG->dirroot . '/theme/boost_campus/locallib.php');
 
 $imageareafiles = theme_boost_campus_get_imageareacontent();
@@ -31,4 +32,7 @@ $imageareafiles = theme_boost_campus_get_imageareacontent();
 // Only proceed if received array is not empty.
 if (!empty($imageareafiles)) {
     $templatecontext['imageareafiles'] = $imageareafiles;
+    $templatecontext['hasimagearea'] = true;
+} else {
+    $templatecontext['hasimagearea'] = false;
 }
diff --git a/locallib.php b/locallib.php
index a215e665558cfc96e2b5d15e02f255a2a88b1fff..f74eaeffaf0cccc72e23bd2e2a655ed3837ab08f 100644
--- a/locallib.php
+++ b/locallib.php
@@ -258,7 +258,8 @@ function theme_boost_campus_get_imageareacontent() {
             $themeboostcampuscache->set('imageareadata', $imageareacache);
             return $imageareacache;
         } else { // If no images are uploaded, then cache an empty array.
-            return $themeboostcampuscache->set('imageareadata', array());
+            $themeboostcampuscache->set('imageareadata', array());
+            return array();
         }
     }
 }
diff --git a/templates/imagearea.mustache b/templates/imagearea.mustache
index 4d8ad44c29eaa8b2e0f4be30d5b4d7da9e03918d..c008db9ef90a0490813c3ae63403261425d58f2a 100644
--- a/templates/imagearea.mustache
+++ b/templates/imagearea.mustache
@@ -20,6 +20,7 @@
     Boost_campus imagearea layout template.
 
     Context variables required for this template:
+    * hasimagearea - true if images have been uploaded.
     * imageareafiles - array of uploaded images.
     * linkpath - true if image has a link defined in setting imageareaitemslink.
     * filepath - the path where the uploaded image is stored.
@@ -27,6 +28,7 @@
 
      Example context (json):
     {
+        "hasimagearea" : true,
         "imageareafiles": {
             "filepath": "/pix/moodlelogo.png",
             "linkpath": "http://moodle.org"
@@ -36,10 +38,10 @@
 
 }}
 
-{{# imageareafiles }}
+{{#hasimagearea}}
 <div class="imagearea d-flex justify-content-center flex-wrap pb-3 bg-dark">
     {{#imageareafiles}}
         {{#linkpath}}<a href="{{linkpath}}">{{/linkpath}}<img src="{{filepath}}" class="mt-3" {{#alttext}} alt="{{alttext}}"{{/alttext}}>{{#linkpath}}</a>{{/linkpath}}
     {{/imageareafiles}}
 </div>
-{{/ imageareafiles }}
+{{/hasimagearea}}
diff --git a/tests/behat/theme_boost_campus_additional_layout_settings.feature b/tests/behat/theme_boost_campus_additional_layout_settings.feature
index e7b1723d7d7da38a19aeb4275927f86d02bd3631..f32bcafdd54ede863e99941475eeadafdc3f22d9 100644
--- a/tests/behat/theme_boost_campus_additional_layout_settings.feature
+++ b/tests/behat/theme_boost_campus_additional_layout_settings.feature
@@ -16,13 +16,19 @@ Feature: Configuring the theme_boost_campus plugin for the "Additional Layout Se
       | teacher1 | C1     | editingteacher |
 
   @javascript @_file_upload
-  Scenario: Add "Image area items"
+  Scenario: Add "Image area items" and delete them again
     When I log in as "admin"
     And I navigate to "Appearance > Boost Campus" in site administration
     And I click on "Additional Layout Settings" "link"
     And I upload "theme/boost_campus/tests/fixtures/moodle_logo.jpg" file to "Image area items" filemanager
     And I press "Save changes"
     Then ".imagearea img" "css_element" should exist
+    And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//img[contains(@src, '/pluginfile.php/1/theme_boost_campus/imageareaitems/0/moodle_logo.jpg')]" "xpath_element" should exist
+    When I navigate to "Appearance > Boost Campus" in site administration
+    And I click on "Additional Layout Settings" "link"
+    And I delete "moodle_logo.jpg" from "Image area items" filemanager
+    And I press "Save changes"
+    Then ".imagearea" "css_element" should not exist
 
   # Dependent on setting "Image area items"
   @javascript @_file_upload