You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/5.x/system/elements.md
+54-10Lines changed: 54 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -178,12 +178,12 @@ A copied [draft](drafts-revisions.md) (provisional or otherwise) is pasted as a
178
178
179
179
## Statuses
180
180
181
-
Most element types support _statuses_. An element’s status is most often a combination of its `enabled` and `enabledForSite` attributes (which Craft stores explicitly for all elements), and any number of other attributes determined by its type. Statuses are represented as strings, and can be accessed via `element.status` in a template, or fed into element query’s `.status()` param as a short-hand for the combination of specific properties they represent.
181
+
Most element types support _statuses_. An element’s status is most often a combination of its `enabled` and `enabledForSite` attributes (which Craft stores explicitly for all elements), and any number of other attributes determined by its [type](#element-types). Statuses are represented as strings, and can be accessed via `element.status` in a template, or fed into element query’s `.status()` param as a short-hand for the combination of specific properties they represent.
182
182
183
183
-**Draft** (`draft`) — The element has a `draftId`.
184
184
-**Archived** (`archived`) — The element’s `archived` property is `true`; currently only used by [user](../reference/element-types/users.md) elements.
185
185
-**Disabled** (`disabled`) — One or both of the `enabled` and `enabledForSite` attributes are `false`.
186
-
-**Enabled** — Both the `enabled`_and_`enabledForSite` attributes are `true`.
186
+
-**Enabled**(`enabled`) — Both the `enabled`_and_`enabledForSite` attributes are `true`.
187
187
188
188
::: tip
189
189
To query for elements without applying _any_ status constraints (including the element type’s defaults), use `query.status(null)`.
@@ -201,7 +201,53 @@ Conversely, disabling an element in a provisional draft may make it _appear_ as
201
201
202
202
</Block>
203
203
204
-
## Nested Elements
204
+
### Querying by Status
205
+
206
+
When querying for elements using the `.status()` param, you’ll need to refer to the list of global identifiers above, and to additional statuses provided by the specific element type:
207
+
208
+
```twig{3,9,15}
209
+
{% set currentDeals = craft.entries()
210
+
.section('deals')
211
+
.status('live')
212
+
.order('postDate DESC')
213
+
.all() %}
214
+
215
+
{% set upcomingDeals = craft.entries()
216
+
.section('deals')
217
+
.status('pending')
218
+
.order('postDate ASC')
219
+
.all() %}
220
+
221
+
{% set pastDeals = craft.entries()
222
+
.section('deals')
223
+
.status('expired')
224
+
.order('expiryDate DESC')
225
+
.all() %}
226
+
```
227
+
228
+
Statuses can be logically combined in a single query, as well:
229
+
230
+
```twig
231
+
{# Two explicit statuses: #}
232
+
{% set bannedUsers = craft.users()
233
+
.status([
234
+
'suspended',
235
+
'locked',
236
+
])
237
+
.all() %}
238
+
239
+
{# One explicit status: #}
240
+
{% set inactiveUsers = craft.users()
241
+
.status('inactive')
242
+
.all() %}
243
+
244
+
{# Negated/inverted status: #}
245
+
{% set inactiveUsersAlt = craft.users()
246
+
.status(['not', 'active'])
247
+
.all() %}
248
+
```
249
+
250
+
## Nested Elements <Badgetext="New!" />
205
251
206
252
Craft ships with two native _nested element_ implementations, which provide unique authoring or administrative experiences:
207
253
@@ -314,11 +360,9 @@ When accessing related or nested content within an element partial, use the `.ea
314
360
315
361
## Properties and Methods
316
362
317
-
<Todonotes="Move to elements reference?" />
318
-
319
363
All elements share a few characteristics that make them familiar to work with in your [templates](../development/templates.md). Each [element type](#element-types) will supplement these lists with their own properties and methods.
320
364
321
-
Additionally, [custom fields](fields.md) attached to an element are automatically made available as properties corresponding to their handles—so a field called “Post Summary” with a handle of `summary` would be accessed as `entry.summary` (if it were attached to an [entry type](../reference/element-types/entries.md#entry-types)’s field layout).
365
+
Additionally, [custom fields](fields.md) attached to an element are automatically made available as properties corresponding to their handles—so a field called “Post Summary” with a handle of `summary` would be accessed as `entry.summary` (if it were attached to an [entry type](../reference/element-types/entries.md#entry-types)’s field layout, and its handle was not overridden).
322
366
323
367
::: warning
324
368
This is not an exhaustive list! If you’re curious, consult the <craft5:craft\base\Element> and <craft5:craft\base\ElementTrait> class reference for a complete picture of what data is available inside elements and how it can be used.
@@ -329,7 +373,7 @@ This is not an exhaustive list! If you’re curious, consult the <craft5:craft\b
329
373
Properties give you access to values, and do not accept arguments.
330
374
331
375
Property | Type | Notes
332
-
-------- | ---- | -----
376
+
--- | --- | ---
333
377
`archived` | `bool|null` | Whether the element is soft-deleted, or “trashed.”
334
378
`dateCreated` | `DateTime` | Date the element was originally created.
335
379
`dateDeleted` | `DateTime|null` | Date the element was soft-deleted or `null` if not.
@@ -352,11 +396,11 @@ Property | Type | Notes
352
396
Methods also return values, but may accept or require arguments.
353
397
354
398
::: tip
355
-
Any method beginning with `get` can be used like a [property](#properties) by removing the prefix and down-casing the first letter. For example, `{{ entry.getLink() }}` can also be accessed as `{{ entry.link }}`
399
+
Any method beginning with `get`(and that accepts no arguments) can be used like a [property](#properties) by removing the prefix and down-casing the first letter. For example, `{{ entry.getLink() }}` can also be used as `{{ entry.link }}` in a template. This is referred to as a “getter” or “magic getter,” and works in part due to the [design of Yii](guide:concept-properties), Craft’s underlying PHP library.
356
400
:::
357
401
358
402
Method | Notes
359
-
------ | -----
403
+
--- | ---
360
404
`getAncestors(dist)` | Returns up to `dist` parents of the element, or all parents when omitted. _Structures only._
361
405
`getChildren()` | Returns immediate children of the element. _Structures only._
362
406
`getCpEditUrl()` | Gets a URL to the Craft control panel.
@@ -367,7 +411,7 @@ Method | Notes
367
411
`getNext(criteria)` | Load the “next” element relative to this one, given a set of criteria.
368
412
`getNextSibling()` | Load the next sibling of this element, within a structure. _Structures only._
369
413
`getOwner()` | Return the element that “owns” a [nested element](../reference/element-types/entries.md#nested-entries). _Nested elements only._
370
-
`getParent()` | Returns the element’s parent. _Structures only._
414
+
`getParent()` | Returns the element’s parent. _Structure elements only._
371
415
`getPrev(criteria)` | Load the previous element relative to this one, given a set of criteria.
372
416
`getPrevSibling()` | Load the previous sibling of this element, within a structure. _Structures only._
373
417
`getRef()` | Builds the part of a [reference tag](reference-tags.md) unique to the element.
0 commit comments