diff --git a/CHANGELOG b/CHANGELOG
index 3181d05e2..6d4feafc4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
* 1.15.0 (2013-XX-XX)
+ * added a source function to include the content of a template without rendering it
* fixed the C extension sandbox behavior when get or set is prepend to method name
* 1.14.2 (2013-10-30)
diff --git a/doc/functions/index.rst b/doc/functions/index.rst
index 8650cbdba..5955e1f54 100644
--- a/doc/functions/index.rst
+++ b/doc/functions/index.rst
@@ -14,4 +14,5 @@ Functions
parent
random
range
+ source
template_from_string
diff --git a/doc/functions/source.rst b/doc/functions/source.rst
new file mode 100644
index 000000000..c2c6adb1b
--- /dev/null
+++ b/doc/functions/source.rst
@@ -0,0 +1,21 @@
+``source``
+==========
+
+.. versionadded:: 1.15
+ The include function was added in Twig 1.15.
+
+The ``source`` function returns the content of a template without rendering it:
+
+.. code-block:: jinja
+
+ {{ source('template.html') }}
+ {{ source(some_var) }}
+
+The function uses the same template loaders as the ones used to include
+templates. So, if you are using the filesystem loader, the templates are looked
+for in the paths defined by it.
+
+Arguments
+---------
+
+* ``name``: The name of the template to read
diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php
index 32d452d34..d25e10885 100644
--- a/lib/Twig/Extension/Core.php
+++ b/lib/Twig/Extension/Core.php
@@ -215,6 +215,7 @@ class Twig_Extension_Core extends Twig_Extension
new Twig_SimpleFunction('random', 'twig_random', array('needs_environment' => true)),
new Twig_SimpleFunction('date', 'twig_date_converter', array('needs_environment' => true)),
new Twig_SimpleFunction('include', 'twig_include', array('needs_environment' => true, 'needs_context' => true, 'is_safe' => array('all'))),
+ new Twig_SimpleFunction('source', 'twig_source', array('needs_environment' => true, 'is_safe' => array('all'))),
);
}
@@ -1370,6 +1371,18 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
}
}
+/**
+ * Returns a template content without rendering it.
+ *
+ * @param string $name The template name
+ *
+ * @return string The template source
+ */
+function twig_source(Twig_Environment $env, $name)
+{
+ return $env->getLoader()->getSource($name);
+}
+
/**
* Provides the ability to get constants from instances as well as class/global constants.
*
diff --git a/test/Twig/Tests/Fixtures/functions/source.test b/test/Twig/Tests/Fixtures/functions/source.test
new file mode 100644
index 000000000..0e094c3b2
--- /dev/null
+++ b/test/Twig/Tests/Fixtures/functions/source.test
@@ -0,0 +1,17 @@
+--TEST--
+"source" function
+--TEMPLATE--
+FOO
+{{ source("foo.twig") }}
+
+BAR
+--TEMPLATE(foo.twig)--
+{{ foo }}
+--DATA--
+return array()
+--EXPECT--
+FOO
+
+{{ foo }}
+
+BAR