I want to write my thesis using a template from the Overleaf Gallery, but there are many empty pages before the acknowledgement, declaration, ToC, before each chapter, etc! How do I get rid of the empty pages?

The blank or gap pages are because the default setting for books (and many thesis templates in the Gallery) is two-sided, with each chapter opening on a right-hand-side ("recto") page, as is the practice for most professionally printed books.

To get rid of these empty pages, just add the oneside option (or alternatively, the openany option) to your document class declaration.