From 1db983c18f8060fac258d7d616b3d4f74ffb4329 Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Fri, 17 May 2013 12:34:59 +1000
Subject: [PATCH 2/2] Add new Twig filter

---
 core/modules/filter/filter.module | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index ea13db2..6a8c637 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -1215,6 +1215,13 @@ function filter_filter_info() {
     'tips callback' => '_filter_html_escape_tips',
     'weight' => -10,
   );
+  $filters['filter_twig'] = array(
+    'title' => t('Process text using the Twig theme engine'),
+    'type' => FILTER_TYPE_MARKUP_LANGUAGE,
+    'description' => t('Allow the processing of the text using the Twig syntax'),
+    'process callback' => '_filter_twig',
+    'tips callback' => '_filter_twig_tips',
+  );
   return $filters;
 }
 
@@ -1764,6 +1771,19 @@ function _filter_html_image_secure_process($text) {
 }
 
 /**
+ * Preprocessing for the Twig Syntax
+ */
+function _filter_twig($text, $context = array()) {
+  $loader = new Twig_Loader_String();
+  $twig = new Twig_Environment($loader);
+  
+  return $twig->render($text, $context);
+}
+
+function _filter_twig_tips() {
+  return t('Use Twig templating engine to render the text, see <a href="http://twig.sensiolabs.org/documentation">http://twig.sensiolabs.org/documentation</a> for more information.');
+}
+/**
  * Formats an image DOM element that has an invalid source.
  *
  * @param DOMElement $image
-- 
1.7.12.4 (Apple Git-37)

