added some tests for the use tag

This commit is contained in:
Fabien Potencier
2011-04-29 09:42:28 +02:00
parent 5ea7020aa0
commit 3930ba0f4e
7 changed files with 96 additions and 2 deletions
+5 -1
View File
@@ -1470,6 +1470,9 @@ http://github.com/fabpot/Twig-extensions.
Horizontal Reuse
----------------
.. versionadded:: 1.1
Horizontal reuse was added in Twig 1.1.
.. note::
Horizontal reuse is an advanced Twig feature that is hardly ever needed in
@@ -1509,7 +1512,8 @@ The ``use`` statement tells Twig to import the blocks defined in
{% block sidebar %}{% endblock %}
In this example, the ``use`` statement imports the ``sidebar`` block into the
main template. The code is exactly equivalent to the following one:
main template. The code is mostly equivalent to the following one (the
imported blocks are not outputted automatically):
.. code-block:: jinja
+1 -1
View File
@@ -163,7 +163,7 @@ class Twig_Node_Module extends Twig_Node
->indent()
;
for ($i = count($this->getNode('traits')) - 1; $i >= 0; --$i) {
for ($i = 0, $count = count($this->getNode('traits')); $i < $count; $i++) {
$compiler
->write(sprintf("\$_trait_%s_blocks,\n", $i))
;
@@ -0,0 +1,12 @@
--TEST--
"use" tag
--TEMPLATE--
{% use "blocks.twig" with content as foo %}
{{ block('foo') }}
--TEMPLATE(blocks.twig)--
{% block content 'foo' %}
--DATA--
return array()
--EXPECT--
foo
@@ -0,0 +1,12 @@
--TEST--
"use" tag
--TEMPLATE--
{% use "blocks.twig" %}
{{ block('content') }}
--TEMPLATE(blocks.twig)--
{% block content 'foo' %}
--DATA--
return array()
--EXPECT--
foo
@@ -0,0 +1,22 @@
--TEST--
"use" tag
--TEMPLATE--
{% use "foo.twig" %}
{{ block('content') }}
{{ block('foo') }}
{{ block('bar') }}
--TEMPLATE(foo.twig)--
{% use "bar.twig" %}
{% block content 'foo' %}
{% block foo 'foo' %}
--TEMPLATE(bar.twig)--
{% block content 'bar' %}
{% block bar 'bar' %}
--DATA--
return array()
--EXPECT--
foo
foo
bar
@@ -0,0 +1,21 @@
--TEST--
"use" tag
--TEMPLATE--
{% use "foo.twig" %}
{% use "bar.twig" %}
{{ block('content') }}
{{ block('foo') }}
{{ block('bar') }}
--TEMPLATE(foo.twig)--
{% block content 'foo' %}
{% block foo 'foo' %}
--TEMPLATE(bar.twig)--
{% block content 'bar' %}
{% block bar 'bar' %}
--DATA--
return array()
--EXPECT--
bar
foo
bar
@@ -0,0 +1,23 @@
--TEST--
"use" tag
--TEMPLATE--
{% use "foo.twig" with content as foo_content %}
{% use "bar.twig" %}
{{ block('content') }}
{{ block('foo') }}
{{ block('bar') }}
{{ block('foo_content') }}
--TEMPLATE(foo.twig)--
{% block content 'foo' %}
{% block foo 'foo' %}
--TEMPLATE(bar.twig)--
{% block content 'bar' %}
{% block bar 'bar' %}
--DATA--
return array()
--EXPECT--
bar
foo
bar
foo