diff --git a/qfq/qfq/Constants.php b/qfq/qfq/Constants.php
index 827bf72..4b9697f 100644
--- a/qfq/qfq/Constants.php
+++ b/qfq/qfq/Constants.php
@@ -1103,6 +1103,7 @@ const SENDMAIL_TOKEN_ATTACHMENT_PAGE = 'p';
 
 // Report, BodyText
 const TOKEN_SQL = 'sql';
+const TOKEN_TWIG = 'twig';
 const TOKEN_HEAD = 'head';
 const TOKEN_ALT_HEAD = 'althead';
 const TOKEN_ALT_SQL = 'altsql';
@@ -1122,7 +1123,7 @@ const TOKEN_FORM = CLIENT_FORM;
 const TOKEN_RECORD_ID = CLIENT_RECORD_ID;
 const TOKEN_DEBUG_BODYTEXT = TYPO3_DEBUG_SHOW_BODY_TEXT;
 
-const TOKEN_VALID_LIST = 'sql|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
+const TOKEN_VALID_LIST = 'sql|twig|head|althead|altsql|tail|shead|stail|rbeg|rend|renr|rsep|fbeg|fend|fsep|rbgd|debug|form|r|debugShowBodyText|sqlLog|sqlLogMode';
 
 const TOKEN_COLUMN_CTRL = '_';
 
diff --git a/qfq/qfq/report/Report.php b/qfq/qfq/report/Report.php
index cfbb6af..7e3d828 100644
--- a/qfq/qfq/report/Report.php
+++ b/qfq/qfq/report/Report.php
@@ -430,13 +430,20 @@ class Report {
             unset($this->variables->resultArray[$full_level . ".line."]["total"]);
             unset($this->variables->resultArray[$full_level . ".line."]["count"]);
 
+
             $sql = $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SQL]);
 
             $this->store->setVar(SYSTEM_SQL_FINAL, $sql, STORE_SYSTEM);
 
+            $twig_template = $this->frArray[$full_level. "." . TOKEN_TWIG];
+            if ($twig_template !== '') {
+                $mode = ROW_REGULAR;
+            } else {
+                $mode = ROW_KEYS;
+            }
             //Execute SQL. All errors have been already catched.
             unset($result);
-            $result = $this->db->sql($sql, ROW_KEYS, array(), '', $keys, $stat);
+            $result = $this->db->sql($sql, $mode, array(), '', $keys, $stat);
 
             // If an array is returned, $sql was a query, otherwise an 'insert', 'update', 'delete', ...
             // Query: total nummber of rows
@@ -447,6 +454,22 @@ class Report {
             $this->variables->resultArray[$full_level . ".line."]["count"] = is_array($result) ? 1 : 0;
             $this->variables->resultArray[$full_level . ".line."]["insertId"] = isset($stat[DB_INSERT_ID]) ? $stat[DB_INSERT_ID] : 0;
 
+	    if ($twig_template !== '') { // twig start
+                require_once '/usr/share/php/Twig/autoload.php';
+		require_once 'TwigExtLink.php';
+		if (in_array(substr($twig_template, 0, 1), array('"', "'"))) {
+			$loader = new \Twig_Loader_Array(array(
+				"string_template" => trim($twig_template, '"\''))
+			);
+			$twig_template = "string_template";
+		} else {
+			$loader = new \Twig_Loader_Filesystem(".");
+		}
+                $twig = new \Twig_Environment($loader, array());
+                $twig->addExtension(new QfqLink_Twig_Extension($this->link));
+                $content .= $twig->render($twig_template, array('context' => $result));
+	    } else { // twig else
+
             $content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_SHEAD]);
             // HEAD: If there is at least one record, do 'head'.
             if ($rowTotal > 0) {
@@ -520,7 +543,7 @@ class Report {
                 }
             }
             $content .= $this->variables->doVariables($this->frArray[$full_level . "." . TOKEN_STAIL]);
-
+	    } // twig end
             ++$counter;
             if (isset($this->indexArray[$counter]) && is_array($this->indexArray[$counter])) {
                 $full_level = implode(".", $this->indexArray[$counter]);
diff --git a/qfq/qfq/report/TwigExtLink.php b/qfq/qfq/report/TwigExtLink.php
new file mode 100644
index 0000000..2a4f2fa
--- /dev/null
+++ b/qfq/qfq/report/TwigExtLink.php
@@ -0,0 +1,58 @@
+<?php
+
+/** LaTeX Filter for Twig
+ *
+ * Based on Code by Seth Fischer
+ * http://seth.fischer.nz/symfony-2-latex-pdf-service.html
+ *
+ */
+
+//use Twig_Extension;
+//use Twig_Filter_Method;
+//use Twig_Test_Method;
+
+namespace qfq;
+
+class QfqLink_Twig_Extension extends \Twig_Extension
+{
+    //private $kernelBundles;
+
+    public function __construct($linkobj)
+    {
+        $this->linkobj = $linkobj;
+    }
+
+    /**
+     * Returns a list of filters to add to the existing list.
+     *
+     * @return array An array of filters
+     */
+    public function getFilters()
+    {
+        return array(
+		'qfqlink'     => new \Twig_Filter_Method($this, 'qfqLink', 
+		    array('is_safe' => array('html'))),
+        );
+    }
+
+    /**
+     * Escape LaTeX special characters
+     *
+     * @return string
+     */
+    public function qfqLink($str = null)
+    {
+	    return $this->linkobj->renderLink($str);
+    }
+
+    /**
+     * Returns the name of the extension
+     *
+     * @return string The extension name
+     */
+    public function getName()
+    {
+        return 'qfq_link_extension';
+    }
+
+}
