diff --git a/views_insert_blocks.module b/views_insert_blocks.module
index e0c71bb..17b4cdc 100644
--- a/views_insert_blocks.module
+++ b/views_insert_blocks.module
@@ -32,11 +32,20 @@ function views_insert_blocks_views_post_render(ViewExecutable $view, array &$out
       $config = \Drupal::service('config.factory')->get('views_insert_blocks.settings');
       $configCacheTags = $config->getCacheTags();
       $view->element['#cache']['tags'] = Cache::mergeTags($configCacheTags, $configCacheTags);
-      /** @var int $currentPage */
-      $currentPage = (int) $view->pager->current_page;
-      // We need to get total elements like this if the view is using mini pager.
-      $totalElements = (int) $view->total_rows;
-      $limit = (int) $view->pager->options['items_per_page'];
+
+      // Initialize pagination variables with default values.
+      $currentPage = 0;
+      $totalElements = 0;
+      $limit = 10;
+
+      // Check if view has results and pagination is enabled.
+      if ($view->pager && !empty($view->result)) {
+        /** @var int $currentPage */
+        $currentPage = (int) $view->pager->current_page;
+        // We need to get total elements like this if the view is using mini pager.
+        $totalElements = (int) $view->total_rows;
+        $limit = (int) $view->pager->options['items_per_page'];
+      }
 
       if (_views_insert_blocks_check_if_should_render($blockConfig, $currentPage, $totalElements, $limit)) {
         // Now set the limit to the number of elements in results because we will be adding them.
@@ -155,7 +164,7 @@ function _views_insert_blocks_check_if_should_render(array $blockConfig, int $pa
   if ($limit < 1) {
     $limit = 1;
   }
-  
+
   $totalPages = (int) ceil($total / $limit) - 1;
 
   if (
