Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Commits on Nov 20, 2014
  1. removed @covers annotations

    authored
Commits on Jan 5, 2014
Commits on May 6, 2013
  1. @Seldaek
Commits on Nov 3, 2012
  1. fixed CS

    authored
Commits on Oct 19, 2012
  1. changed Node instances line numbers from 0 to 1 in unit tests to bett…

    authored
    …er reflect what really happens when using Twig
Commits on Sep 18, 2012
  1. Made node tests reusable

    Drak authored
Commits on Feb 6, 2012
Commits on Dec 21, 2011
  1. @nikic

    Fix test for previous commit

    nikic authored
Commits on Nov 18, 2011
Commits on Nov 7, 2011
Commits on Nov 4, 2011
Commits on Sep 30, 2011
  1. fixed hardcoded name escaping

    authored
Commits on Sep 1, 2011
Commits on Aug 6, 2011
  1. merged branch kotas/master (PR #362)

    authored
    Commits
    -------
    
    f5b9df9 added `if` modifier support to for loop like {% for k in v if k is odd %}
    
    Discussion
    ----------
    
    [1.2] added `if` modifier support to for loop
    
    Hi.
    
    I'm one of Twig users who love it so much. :)
    
    I've made a patch for adding `if` modifier support to `for` loop in Twig.
    
    Example:
    <pre>
    {% for n in range(0, 5) if n is odd %}
      {{ n }}
    {% endfor %}
    </pre>
    
    Output:
    <pre>
    1
    3
    5
    </pre>
    
    This idea comes from Python's list comprehensions. (like `[n for n in range(0,6) if n % 2 == 1]`)
    
    Here is another example.
    
    Before:
    <pre>
    {% set no_items = true %}
    {% for item in items %}
      {% if item.available %}
        {% set no_items = false %}
        {{ item.name }}
      {% endif %}
    {% endfor %}
    {% if no_items %}
      No items available.
    {% endif %}
    </pre>
    
    After:
    <pre>
    {% for item in items if item.available %}
      {{ item.name }}
    {% else %}
      No items available.
    {% endfor %}
    </pre>
    
    I hope you like it. But If not, just ignore this request. :)
    
    Thanks.
    
    ---------------------------------------------------------------------------
    
    by fabpot at 2011/06/24 01:33:33 -0700
    
    I like it! I will schedule it for inclusion in Twig 1.2. Thanks.
    
    ---------------------------------------------------------------------------
    
    by hhamon at 2011/06/26 16:43:26 -0700
    
    +1
    
    ---------------------------------------------------------------------------
    
    by nikic at 2011/06/27 00:42:14 -0700
    
    I think the idea per se is interesting. But I just checked all Twig templates in my whole codebase and couldn't find any use for it. What was your practical use for this feature @kotas?
    
    ---------------------------------------------------------------------------
    
    by kotas at 2011/06/27 01:52:48 -0700
    
    @nikic My practical use is shown as the second example in the body of this pull request.
    
    Sometimes you need to "filter" an array by seeing its element's property like "item.available" or by some condition like "item.price >= 500".
    
    To do this, in the current version of Twig, you have to write "for" and "if" as nested scopes. And if you want to write {% else %} of the "for" loop, you have to make a temporary variable to see if all elements are skipped.
    
    I think this feature is not essential, but makes templates clean.
    
    ---------------------------------------------------------------------------
    
    by nikic at 2011/06/27 06:23:24 -0700
    
    The thing about `else` seems plausible. +1
    
    ---------------------------------------------------------------------------
    
    by chucktrukk at 2011/08/02 17:39:16 -0700
    
    Also +1. that makes some very clean template code.
Commits on Jul 2, 2011
  1. @nikic

    Update tests

    nikic authored
Commits on Jun 17, 2011
  1. @kotas
Commits on Dec 30, 2010
Commits on Dec 18, 2010
  1. some improvements to for tag compiler

    nikic authored committed
Commits on Dec 13, 2010
Commits on Nov 28, 2010
  1. @Seldaek

    Added joined by statement to for loops

    Seldaek authored committed
Commits on Oct 2, 2010
  1. changed the way to access nodes and attributes from a node

    authored
    Before:
      Nodes were accessed via node properties ($node->body)
      Attributes were accessed via node array access ($node['name'])
    
    After:
      Nodes are accessed via getNode(), setNode(), ... ($node->getNode('body'))
      Attributes are accessed via getAttribute(), setAttribute(), ... ($node->getAttribute('name'))
    
    The change was necessary because of side-effects. This is one more time the
    demonstration that being explicit is always better than magic ;)
Commits on Jun 12, 2010
Commits on Jun 7, 2010
  1. fixed the for tag for large arrays (closes #64 - based on an idea fro…

    authored
    …m gwilym - aeb56f9f966bd23b77d35c87999be0606dbb3f47)
Commits on Jun 3, 2010
Something went wrong with that request. Please try again.