diff --git a/templates/includes/footer.php b/templates/includes/footer.php
index 7f6fe648ce5598437efe376e1c08fa217bf38afe..42c8394d9c1cafb1b2f431a6b3c88e7af8e7490b 100644
--- a/templates/includes/footer.php
+++ b/templates/includes/footer.php
@@ -1,12 +1,14 @@
+<?php
 
 
-<?php
 
-if(isset($htmlContentPost)) {
-	foreach($htmlContentPost AS $c) {
+if(!empty($this->data['htmlinject']['htmlContentPost'])) {
+	foreach($this->data['htmlinject']['htmlContentPost'] AS $c) {
 		echo $c;
 	}
 }
+
+
 ?>
 
 
diff --git a/templates/includes/header.php b/templates/includes/header.php
index c537af760cfb88dc1e60440593af6970f612e627..c8ac0edc3b018bc1a4e81a0ec2a3cc9b15171721 100644
--- a/templates/includes/header.php
+++ b/templates/includes/header.php
@@ -6,14 +6,25 @@
 /**
  * Support the htmlinject hook, which allows modules to change header, pre and post body on all pages.
  */
-$htmlContentPre = array(); $htmlContentPost = array(); $htmlContentHead = array(); 
+$this->data['htmlinject'] = array(
+	'htmlContentPre' => array(),
+	'htmlContentPost' => array(),
+	'htmlContentHead' => array(),
+);
+
 
 $jquery = array();
 if (array_key_exists('jquery', $this->data)) $jquery = $this->data['jquery'];
 
-
 if (array_key_exists('pageid', $this->data)) {
-	$hookinfo = array('pre' => &$htmlContentPre, 'post' => &$htmlContentPost, 'head' => &$htmlContentHead, 'jquery' => &$jquery, 'page' => $this->data['pageid']);
+	$hookinfo = array(
+		'pre' => &$this->data['htmlinject']['htmlContentPre'], 
+		'post' => &$this->data['htmlinject']['htmlContentPost'], 
+		'head' => &$this->data['htmlinject']['htmlContentHead'], 
+		'jquery' => &$jquery, 
+		'page' => $this->data['pageid']
+	);
+		
 	SimpleSAML_Module::callHooks('htmlinject', $hookinfo);	
 }
 // - o - o - o - o - o - o - o - o - o - o - o - o -
@@ -68,6 +79,13 @@ if(!empty($jquery)) {
 	}
 }
 
+if(!empty($this->data['htmlinject']['htmlContentHead'])) {
+	foreach($this->data['htmlinject']['htmlContentHead'] AS $c) {
+		echo $c;
+	}
+}
+
+
 
 
 ?>
@@ -166,8 +184,8 @@ if($onLoad !== '') {
 
 <?php
 
-if(isset($htmlContentPre)) {
-	foreach($htmlContentPre AS $c) {
+if(!empty($this->data['htmlinject']['htmlContentPre'])) {
+	foreach($this->data['htmlinject']['htmlContentPre'] AS $c) {
 		echo $c;
 	}
 }