diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index a0415a4a0bf5e4daac1a59f30ce3958cf012d193..9df0554f75957ce64d6a16b03610f06cda21ea81 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -175,10 +175,10 @@ class Template extends Response
             $this->controller = new $controller();
         }
 
+        $this->fileSystem = new Filesystem();
         $this->twig = $this->setupTwig();
-
         $this->charset = 'UTF-8';
-        $this->fileSystem = new Filesystem();
+
         parent::__construct();
     }