mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-11 09:56:32 +00:00
Merge branch '1.x'
* 1.x: fixed PHP 5.2 compat tweaked previous merge add ignore_missing agrument to source function updated CHANGELOG
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
* 1.18.3 (2015-XX-XX)
|
||||
|
||||
* added ignore_missing flag to the source function
|
||||
* fixed batch filter with zero items
|
||||
* deprecated Twig_Environment::clearTemplateCache()
|
||||
* fixed sandbox disabling when using the include function
|
||||
|
||||
|
||||
@@ -8,6 +8,13 @@ The ``source`` function returns the content of a template without rendering it:
|
||||
{{ source('template.html') }}
|
||||
{{ source(some_var) }}
|
||||
|
||||
When you set the ``ignore_missing`` flag, Twig will return an empty string if
|
||||
the template does not exist:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{{ source('template.html', ignore_missing = true) }}
|
||||
|
||||
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.
|
||||
@@ -16,3 +23,4 @@ Arguments
|
||||
---------
|
||||
|
||||
* ``name``: The name of the template to read
|
||||
* ``ignore_missing``: Whether to ignore missing templates or not
|
||||
|
||||
@@ -1400,13 +1400,20 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
|
||||
/**
|
||||
* Returns a template content without rendering it.
|
||||
*
|
||||
* @param string $name The template name
|
||||
* @param string $name The template name
|
||||
* @param bool $ignoreMissing Whether to ignore missing templates or not
|
||||
*
|
||||
* @return string The template source
|
||||
*/
|
||||
function twig_source(Twig_Environment $env, $name)
|
||||
function twig_source(Twig_Environment $env, $name, $ignoreMissing = false)
|
||||
{
|
||||
return $env->getLoader()->getSource($name);
|
||||
try {
|
||||
return $env->getLoader()->getSource($name);
|
||||
} catch (Twig_Error_Loader $e) {
|
||||
if (!$ignoreMissing) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,9 +86,12 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// avoid using the same PHP class name for different cases
|
||||
$p = new ReflectionProperty($twig, 'templateClassPrefix');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_');
|
||||
// only for PHP 5.2+
|
||||
if (PHP_VERSION_ID >= 50300) {
|
||||
$p = new ReflectionProperty($twig, 'templateClassPrefix');
|
||||
$p->setAccessible(true);
|
||||
$p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_');
|
||||
}
|
||||
|
||||
try {
|
||||
$template = $twig->loadTemplate('index.twig');
|
||||
|
||||
Reference in New Issue
Block a user