2017 © Pedro Peláez
 

library twig-only-once

Twig test which returns true only once per value.

image

dpolac/twig-only-once

Twig test which returns true only once per value.

  • Saturday, April 30, 2016
  • by dpolac
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

OnlyOnce Twig Extension

Twig test which returns true only once per value., (*1)

Made to aid in looping through unique values., (*2)

    {% for article in articles if article.category is onlyOnce %}
        * {{ article.category }}
    {% endfor %}

Installation

  • Install via Composer:
    composer require dpolac/twig-only-once
  • Add the extension to Twig:
    $twig->addExtension(new \DPolac\OnlyOnce\OnlyOnceExtension());

Usage

Extension provides two tests onlyOnce and onlyOnceWhenOccurs., (*3)

is onlyOnce

    {% if value is onlyOnce %} ... {% endif %}
    {% if value is onlyOnce(space) %} ... {% endif %}

Test returns true only when it's called for the first time with given value and space pair., (*4)

Arguments

  • value: can be value of any type
    • number - is converted to string, so 12 and '12' are treated as same value,
    • string,
    • object - are compared by reference, so new \stdClass() and new \stdClass() are treated as different value,
    • array - to arrays are treated as same value when have exactly same key-value set; order of keys in hashes is ignored,
  • space: can be any string (default: 'default')

is onlyOnceWhenOccurs

    {% if value is onlyOnceWhenOccurs(n) %} ... {% endif %}
    {% if value is onlyOnceWhenOccurs(n, space) %} ... {% endif %}

Test returns true only when it's called for the n-th time with given value and space pair. Note that onlyOnce is an alias to onlyOnceWhenOccurs(1), so they share internal occurrences' counter., (*5)

Arguments

  • value: as in onlyOnce,
  • n: number of occurrences after which test returns true,
  • space: can be any string (default: 'default').

Examples

Check tests in ./Tests/Fixtures/ directory for more examples., (*6)

The Versions

30/04 2016

dev-master

9999999-dev

Twig test which returns true only once per value.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Damian Polac

filter unique distinct

30/04 2016

v1.0.0

1.0.0.0

Twig test which returns true only once per value.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Damian Polac

filter unique distinct