gglnx/twig-empty-coalesce
最新稳定版本:1.0.1
Composer 安装命令:
composer require gglnx/twig-empty-coalesce
包简介
The empty test and default filter as an operator
关键字:
README 文档
README
This library adds a new operator expression to Twig with three question marks (???) to check if the left value is defined, not null and not empty. Works the same way as the empty test and the |default filter.
{% set _null = null %}
{% set _empty = '' %}
{# Null Coalesce: Output will be string(0) "" because _empty is defined and not exactly null #}
{{ dump(_undefined ?? _null ?? _empty ?? 'fallback') }}
{# Default Filter: Output will be string(8) "fallback" because _empty is defined, but an empty string #}
{{ dump(_undefined | default(_null | default(_empty | default('fallback')))) }}
{# Same as the default filter, but much more readable #}
{{ dump(_undefined ??? _null ??? _empty ??? 'fallback') }}
Requirements
- Twig >=2.14 and Twig >=3.0
- PHP >=7.4
Installation
The recommended way to install this loader is via Composer:
composer require gglnx/twig-empty-coalesce
You can install this library as extension in:
require_once '/path/to/vendor/autoload.php'; $twig = new \Twig\Environment($loader); $twig->addExtension(new \Gglnx\TwigEmptyCoalesce\Extension\EmptyCoalesceExtension());
统计信息
- 总下载量: 6.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-05