定制 dpolac/twig-only-once 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dpolac/twig-only-once

Composer 安装命令:

composer require dpolac/twig-only-once

包简介

Twig test which returns true only once per value.

README 文档

README

Twig test which returns true only once per value.

Made to aid in looping through unique values.

    {% 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.

###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.

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.

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.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固