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
This returns an array of [Country](https://github.com/commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a drop-down menu:
118
+
This returns an array of [Country](https://github.com/commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a dropdown menu:
`primarySite` will be a reference to the same object as [`currentSite`](#currentsite), when `currentSite.primary` is `true`. You can also retrieve the primary site via `craft.app.sites.primarySite`.
238
+
221
239
### `setPasswordUrl`
222
240
223
241
The URL to [`setPasswordRequestPath`](config4:setPasswordRequestPath) if it’s set. (This wraps the path in [`siteUrl`](#siteurl).)
This returns an array of [Country](repo:commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a drop-down menu:
110
+
This returns an array of [Country](repo:commerceguys/addressing/blob/master/src/Country/Country.php) objects, indexed by their two-letter code. You might use this to populate a dropdown menu:
Copy file name to clipboardExpand all lines: docs/5.x/reference/element-types/entries.md
+63-10Lines changed: 63 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -24,17 +24,18 @@ Craft uses _entry types_ to define atomic units of content, which are then expos
24
24
25
25
<Blocklabel="Global Entry Types">
26
26
27
-
Entry types became a global resource in Craft 5. This means you can define a content type _once_, then use it in multiple sections, as a [nested](#nested-entries) block in a Matrix field, or some combination of the two. As a result, some settings have moved around!
27
+
Entry types became a global resource in Craft 5. This means you can define a content type _once_, then use it in multiple sections, as a [nested](#nested-entries) block in a [Matrix](../field-types/matrix.md) field, or some combination of the two. As a result, some settings have moved around!
28
28
29
29
Most importantly, you’ll manage entry types in the **Settings**→**Entry Types** screen—or create them on-the-fly when working on a section or Matrix field.
caption="Editing an entry type in the control panel.">
37
-
<imgsrc="../../images/sections-and-entries-entry-types.png"alt="Screenshot of entry type settings">
38
+
<imgsrc="../../images/entry-type-edit.png"alt="Screenshot of entry type settings">
38
39
</BrowserShot>
39
40
40
41
Entry types have the following settings:
@@ -49,6 +50,58 @@ Entry types have the following settings:
49
50
-**Show the Status field** — Manually set each entry’s status, or allow it to be dictated by its usage.
50
51
-**Field Layout** — Add and arrange [custom fields](../../system/fields.md) to suit your content model.
51
52
53
+
### Aliases <Sincever="5.6.0"feature="Entry type aliases" />
54
+
55
+
When attaching an entry type to a [section](#sections) or [field](../field-types/matrix.md), you can configure a local override for its **Name** and **Handle**. This affects labels in the control panel, but does _not_ change how you reference them in queries.
56
+
57
+
As an example, an _Announcement_ entry type could be used in a _News_ section and a _Content_ Matrix or [CKEditor](plugin:ckeditor) field; in the _Content_ field context, the entry type is given a new **Name** (_Banner_) and handle (`banner`). Authors would then see _Banner_ when selecting **New entry** in the CKEditor toolbar, but developers would need to continue using the original, global handle to directly query those nested entries:
58
+
59
+
```twig{3}
60
+
{% set embeddedAnnouncements = craft.entries()
61
+
.field('pageContent')
62
+
.type('announcement')
63
+
.all() %}
64
+
```
65
+
66
+
However, when _accessing_ the entry type via those nested entries (or an entry within a section), the aliases are applied automatically:
In this example, `announcement.type.name` might resolve to _Critical Release_ in one section, but _New Face_ in another—even though we queried for them using the original, global handle. To access the global <craft5:craft\models\EntryType>, use `entry.type.original`.
83
+
84
+
This can help improve the legibility of templates, wherein the generic `announcement` handle doesn’t describe how the entry type is actually used:
{# Perhaps “Banner” made more sense than “Announcement” in this context, when designing! #}
96
+
<h3>{{ contentBlock.title }}</h3>
97
+
{{ contentBlock.message|md }}
98
+
{% default %}
99
+
{{ contentBlock.render() }}
100
+
{% endswitch %}
101
+
</div>
102
+
{% endfor %}
103
+
```
104
+
52
105
### Dynamic Entry Titles
53
106
54
107
The **Default Title Format** field accepts an [object template](../../system/object-templates.md) (just like the **Entry URI Format** and preview target **URL Format** we looked, above), and is evaluated whenever entries with this type are saved _without an explicitly-set title_. A title format may be rendered multiple times, depending on the selected **Title Translation Method**.
@@ -67,7 +120,7 @@ The available translation methods are covered in the [custom fields documentatio
67
120
68
121
## Sections
69
122
70
-
Sections organize and expose entry types for content authors. In each section you can define the following:
123
+
Sections organize and expose [entry types](#entry-types) for content authors. In each section you can define the following:
71
124
72
125
- Whether entries in the section have URLs;
73
126
- What the entries’ URLs should look like;
@@ -80,15 +133,15 @@ If your project has multiple [sites](../../system/sites.md), your section can de
80
133
- Which sites entries in the section should target;
81
134
- Which sites entries are created in, by default;
82
135
83
-
To create a new section, go to **Settings** → **Sections** and choose **New Section**.
136
+
To create a new section, go to <Journeypath="Settings, Sections" /> and choose **New Section**.
84
137
85
138
### Section Types
86
139
87
140
Craft has three different types of sections:
88
141
89
142
#### Singles
90
143
91
-

144
+

92
145
93
146
Singles are used for one-off pages or content objects that have unique requirements, such as…
94
147
@@ -106,7 +159,7 @@ A single’s **Status** controls can be hidden with the **Show the Status field*
106
159
107
160
#### Channels
108
161
109
-

162
+

110
163
111
164
Channels are used for lists or streams of similar content, such as…
112
165
@@ -121,11 +174,11 @@ Entries in channels are intended to be queried and displayed ordered by one or m
121
174
122
175
Structures are an extension of channels that support explicit, hierarchical organization.
123
176
124
-

177
+

125
178
126
179
Unlike other section types, structure sections expose a **Structure** view option on their [element indexes](../../system/elements.md#indexes):
127
180
128
-

181
+

129
182
130
183
Types of content that might benefit from being defined as a structure include…
131
184
@@ -166,7 +219,7 @@ When Craft matches a request to an entry, its section’s designated **Template*
166
219
167
220
Consider these tips for creating special URIs:
168
221
169
-
- A URI that evaluates to `__home__` (and nothing more) will be available at your site’s base path;
222
+
- A URI that evaluates to `__home__` (and nothing more) will be available at your site’s base path (this should only be used for [singles](#singles));
170
223
- An empty URI means the entry does not get a route and will not have a public URL—unless you define one manually via `routes.php`;
171
224
- Any Twig statement can be used to output values in a URI template—including ones that query for other elements, e.g. `{{ craft.entries().section('mySingle').one().slug }}/news` (see note below);
172
225
-[Aliases](../../configure.md#aliases-and-environment-variables) can be evaluated with the [`alias()` function](../twig/functions.md#alias): `{{ alias('@basePressUri') }}/news`, `{{ alias('@mySectionUri') }}`.
Copy file name to clipboardExpand all lines: docs/5.x/reference/element-types/users.md
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,18 @@ By {{ collect(entry.authors).pluck('fullName').join(', ', ', and ') }}
92
92
93
93
Unlike most other element types, users do _not_ have a “URI format” setting or support slugs, and are not factored into routing.
94
94
95
+
### Affiliated Site <Sincever="5.6.0"feature="Affiliated sites for user elements" />
96
+
97
+
[Multi-site](../../system/sites.md) projects capture the site a user [registers](../../system/user-management.md#affiliated-site) from (or is assigned to by an admin). Add the **Affiliated Site**[field layout element](#custom-fields) to manage this in the control panel.
98
+
99
+
A user’s affiliated site can be accessed in a template via `user.affiliatedSite`:
100
+
101
+
```twig
102
+
{% if currentUser.affiliatedSite %}
103
+
You registered via {{ currentUser.affiliatedSite.name }}.
104
+
{% endif %}
105
+
```
106
+
95
107
## Querying Users
96
108
97
109
You can fetch users in your templates or PHP code using **user queries**.
Color fields give you a hexadecimal color input with a preview of the current color, and on browsers that support `<input type="color">`, clicking on the preview will open the browser’s color picker.
3
+
Color fields provide a flexible way to store hexadecimal color values. You can define a [palette](#palette) to guide authors <Sincever="5.6.0"feature="Color field palettes" />, or use an [open-ended input](#custom-colors).
4
4
5
5
<!-- more -->
6
6
7
+

caption="Adding a new color field via the control panel.">
16
+
<imgsrc="../../images/fields-color-settings.png"alt="Color field settings screen in the Craft control panel">
17
+
</BrowserShot>
18
+
19
+
### Palette
20
+
21
+
Each field contains a **Palette** of colors that authors can select from a dropdown menu.
22
+
23
+
### Custom Colors
24
+
25
+
Turn on **Allow custom colors** to display a compact input and color preview UI. When used in conjunction with a palette, an additional **Custom…** option is listed at the bottom of the dropdown menu.
26
+
27
+
::: tip
28
+
In [browsers that support `<input type="color">`](https://caniuse.com/input-color), clicking on the color preview “well” opens a native OS color picker.
29
+
:::
30
+
7
31
## Development
8
32
9
-
Calling a Color field in your templates will return a <craft5:craft\fields\data\ColorData> object, or `null` if no color was selected.
33
+
Accessing a color field returns a <craft5:craft\fields\data\ColorData> object, or `null` if no color was selected.
10
34
11
-
By default, the bare field handle will return a hexadecimal representation of that color:
35
+
Casting a `ColorData` object to a string by outputting it directly produces a hexadecimal representation of the color:
12
36
13
37
::: code
14
38
```twig
15
-
{% if entry.myFieldHandle %}
39
+
{% if entry.myColorField %}
16
40
<style type="text/css">
17
41
.content a {
18
-
color: {{ entry.myFieldHandle }};
42
+
{# Directly outputting the value... #}
43
+
color: {{ entry.myColorField }};
19
44
}
20
45
.content b {
21
-
{# same thing #}
22
-
color: {{ entry.myFieldHandle.getHex() }};
46
+
{# ...is equivalent to: #}
47
+
color: {{ entry.myColorField.getHex() }};
23
48
}
24
49
</style>
25
50
{% endif %}
26
51
```
27
52
```php
28
-
if ($entry->myFieldHandle) {
29
-
echo $entry->myFieldHandle;
30
-
// same thing
31
-
echo $entry->myFieldHandle->getHex();
53
+
if ($entry->myColorField) {
54
+
echo $entry->myColorField;
55
+
// …is equivalent to…
56
+
echo $entry->myColorField->getHex();
32
57
}
33
58
```
34
59
:::
35
60
36
-
Here’s an impractical example illustrating each <craft5:craft\fields\data\ColorData> method:
61
+
`ColorData` objects have a number of methods that streamline working with color values:
The example omits the `getL()`, `getS()`, `getR()`, `getG()`, and `getB()` methods, which are abbreviated forms of `getLuma()`, `getSaturation()`, `getRed()`, `getGreen()`, and `getBlue()` respectively.
97
+
Refer to the [`ColorData`](craft5:craft\fields\data\ColorData) class reference for a complete list of methods!
73
98
:::
99
+
100
+
## Querying by Color
101
+
102
+
There are no special query features for color fields; refer to the [plain text](plain-text.md) field for a list of standard string comparison syntaxes.
0 commit comments