mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Merge branch '1.x'
* 1.x: fixed edge case where tests would fail because of a cache issue tweaked docs to avoid using an internal method in an example deprecated Twig_Environment::clearTemplateCache() fixed sandbox disabling when using the include function Example about how to rename several blocks fixed docs Update batch filter docs with arguments
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
|
||||
* 1.18.3 (2015-XX-XX)
|
||||
|
||||
* n/a
|
||||
* deprecated Twig_Environment::clearTemplateCache()
|
||||
* fixed sandbox disabling when using the include function
|
||||
|
||||
* 1.18.2 (2015-06-06)
|
||||
|
||||
|
||||
@@ -40,3 +40,9 @@ The above example will be rendered as:
|
||||
<td>No item</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Arguments
|
||||
---------
|
||||
|
||||
* ``size``: The size of the batch; fractional numbers will be rounded up
|
||||
* ``fill``: Used to fill in missing items
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ using)::
|
||||
{
|
||||
// line 1
|
||||
echo "Hello ";
|
||||
echo twig_escape_filter($this->env, $this->getContext($context, "name"), "html", null, true);
|
||||
echo twig_escape_filter($this->env, isset($context["name"]) ? $context["name"] : null), "html", null, true);
|
||||
}
|
||||
|
||||
// some more code
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ is ignored. To avoid name conflicts, you can rename imported blocks:
|
||||
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% use "blocks.html" with sidebar as base_sidebar %}
|
||||
{% use "blocks.html" with sidebar as base_sidebar, title as base_title %}
|
||||
|
||||
{% block sidebar %}{% endblock %}
|
||||
{% block title %}{% endblock %}
|
||||
|
||||
@@ -439,6 +439,8 @@ class Twig_Environment
|
||||
|
||||
/**
|
||||
* Clears the internal template cache.
|
||||
*
|
||||
* @deprecated since 1.18.3 (to be removed in 2.0)
|
||||
*/
|
||||
public function clearTemplateCache()
|
||||
{
|
||||
|
||||
@@ -1377,10 +1377,15 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
|
||||
}
|
||||
}
|
||||
|
||||
$result = null;
|
||||
try {
|
||||
return $env->resolveTemplate($template)->render($variables);
|
||||
$result = $env->resolveTemplate($template)->render($variables);
|
||||
} catch (Twig_Error_Loader $e) {
|
||||
if (!$ignoreMissing) {
|
||||
if ($isSandboxed && !$alreadySandboxed) {
|
||||
$sandbox->disableSandbox();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@@ -1388,6 +1393,8 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
|
||||
if ($isSandboxed && !$alreadySandboxed) {
|
||||
$sandbox->disableSandbox();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
|
||||
$loader = new Twig_Loader_Array($templates);
|
||||
|
||||
foreach ($outputs as $match) {
|
||||
foreach ($outputs as $i => $match) {
|
||||
$config = array_merge(array(
|
||||
'cache' => false,
|
||||
'strict_variables' => true,
|
||||
@@ -85,6 +85,11 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$twig->addExtension($extension);
|
||||
}
|
||||
|
||||
// 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).'_');
|
||||
|
||||
try {
|
||||
$template = $twig->loadTemplate('index.twig');
|
||||
} catch (Exception $e) {
|
||||
@@ -129,7 +134,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
|
||||
$expected = trim($match[3], "\n ");
|
||||
|
||||
if ($expected != $output) {
|
||||
echo 'Compiled template that failed:';
|
||||
printf("Compiled templates that failed on case %d:\n", $i + 1);
|
||||
|
||||
foreach (array_keys($templates) as $name) {
|
||||
echo "Template: $name\n";
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
"include" tag sandboxed
|
||||
--TEMPLATE--
|
||||
{{ include("foo.twig", sandboxed = true) }}
|
||||
{{ include("bar.twig") }}
|
||||
--TEMPLATE(foo.twig)--
|
||||
foo
|
||||
--TEMPLATE(bar.twig)--
|
||||
{{ foo|e }}
|
||||
--DATA--
|
||||
return array('foo' => 'bar<br />')
|
||||
--EXPECT--
|
||||
foo
|
||||
|
||||
|
||||
bar<br />
|
||||
@@ -0,0 +1,13 @@
|
||||
--TEST--
|
||||
"include" tag sandboxed
|
||||
--TEMPLATE--
|
||||
{{ include("unknown.twig", sandboxed = true, ignore_missing = true) }}
|
||||
{{ include("bar.twig") }}
|
||||
--TEMPLATE(bar.twig)--
|
||||
{{ foo|e }}
|
||||
--DATA--
|
||||
return array('foo' => 'bar<br />')
|
||||
--EXPECT--
|
||||
|
||||
|
||||
bar<br />
|
||||
Reference in New Issue
Block a user