--- /dev/null
+``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
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'))),
);
}
}
/**
+ * 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.
*
* @param string $constant The name of the constant