fixed loop.last when the array only has one item (closes #40)

git-svn-id: http://svn.twig-project.org/trunk@148 93ef8e89-cb99-4229-a87c-7fa0fa45744b
This commit is contained in:
fabien
2009-12-01 15:15:03 +00:00
parent 2ffcea6c3d
commit a59e183f73
2 changed files with 6 additions and 5 deletions
+1
View File
@@ -4,6 +4,7 @@ If you have custom loaders, you MUST upgrade them for this release: The
Twig_Loader base class has been removed, and the Twig_LoaderInterface has also
been changed (see the source code for more information or the documentation).
* fixed loop.last when the array only has one item
* made it possible to insert newlines in tag and variable blocks
* fixed a bug when a literal '\n' were present in a template text
* refactored loaders
+5 -5
View File
@@ -72,17 +72,17 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface
->write("\$seq$var = twig_iterator_to_array(")
->subcompile($this->seq)
->raw(");\n")
->write("\$context['loop']['length'] = count(\$seq$var);\n")
->write("\$length = count(\$seq$var);\n")
->write("\$context['loop'] = array(\n")
->write(" 'parent' => \$context['_parent'],\n")
->write(" 'length' => \$context['loop']['length'],\n")
->write(" 'length' => \$length,\n")
->write(" 'index0' => 0,\n")
->write(" 'index' => 1,\n")
->write(" 'revindex0' => \$context['loop']['length'] - 1,\n")
->write(" 'revindex' => \$context['loop']['length'],\n")
->write(" 'revindex0' => \$length - 1,\n")
->write(" 'revindex' => \$length,\n")
->write(" 'first' => true,\n")
->write(" 'last' => false,\n")
->write(" 'last' => 1 === \$length,\n")
->write(");\n")
->write("foreach (\$seq$var as \$context[")