mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 19:36:43 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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[")
|
||||
|
||||
Reference in New Issue
Block a user