Document how conditions treat empty and null values
维护者通常 1 天内回复
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 25/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- php
调研方向
The change belongs on the conditions page of the docs, under the 'Using a variable reference' section. To confirm the behaviour, read Statamic\Tags\Concerns\QueriesConditions::queryableConditionParams() in statamic/cms, which skips parameters whose value is an empty string but passes null through. Done means the note is in the docs, but PR #2001 is already open with this wording, so check that PR before writing anything new.
由索引模型根据 Issue 内容生成。
描述
The conditions page doesn't say what a condition does when its value is empty or null. Two different things happen, depending on how the value is passed. Both are easy to hit when the value comes from something that can be blank, such as a query-string value, an optional field or an empty picker.
Measured on statamic/cms v6.26.0, with the collection tag on a collection of 75 published entries:
| Template | Value the tag receives | Result |
|---|---|---|
type:is="", or type:is="{{ get:type }}" when type is absent from the query string |
'' |
The condition is skipped: all 75 entries are returned |
:type:is="some_var" when some_var is null or not set |
null |
Filters to entries where type is null, so only entries without that field are returned |
:type:is="some_var" when some_var is '' |
'' |
The condition is skipped, as in the first row |
The skip comes from Statamic\Tags\Concerns\QueriesConditions::queryableConditionParams(), which rejects any parameter whose value is ''. A null is not rejected, so it reaches $query->where($field, null).
Both behaviors seem reasonable. What's missing is a note saying so, because the two forms look interchangeable and do opposite things when the value is blank. The first lists everything; the second can list nothing, for example on blueprint, which every entry has.
Suggested wording, under Using a variable reference:
If a condition's value is an empty string, the condition is skipped and the results are not filtered by it. If a variable reference (
:field:is="variable") resolves tonull, the condition filters for entries where that field is empty.
Docs PR with that wording: #2001.
- 主要语言
- PHP
- 星标
- 133
- 派生
- 405
- 平均合并
- 21 小时 45 分钟
- 30 天内合并 PR
- 12
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
statamic/docs 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复
-
Chunked Uploads未关闭
难度 1/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Installation / Deployment Guides
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 40/100
维护者通常 1 天内回复
-
Document the `query_scope` search index option可能已有人在做 @joshdaugherty 于 12 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 18/100
维护者通常 1 天内回复
相似的 Issue
-
needs-triage Platform(Default)
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Feature-Request
难度 2/5 1-3 小时 新手友好度 65/100
RSS-Bridge/rss-bridge#5123 ·
维护者通常 1 天内回复
-
[Store] RstLoader detects headings inside indented code blocks可能已有人在做 @lazerg 今天认领。 未关闭Bug Status: Needs Review Store
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug repo:ckeditor
难度 2/5 1-3 小时 新手友好度 78/100
-
No Code Attached Yet
难度 2/5 1-3 小时 新手友好度 72/100
joomla/joomla-cms#48611 ·
维护者通常 1 天内回复