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 天內回覆