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/reference/element-types/addresses.md
+52-52Lines changed: 52 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -48,58 +48,6 @@ Addresses can be copied and pasted between users and [addresses fields](../field
48
48
49
49
<Seepath="../../system/elements.md"hash="copying-elements"label="Copying Elements"description="Learn how to copy addresses and other elements between contexts." />
50
50
51
-
## Querying Addresses
52
-
53
-
You can fetch addresses in your templates or PHP code using an [AddressQuery](craft5:craft\elements\db\AddressQuery).
<Seepath="../../development/element-queries.md"label="Introduction to Element Queries"description="Learn more about how element queries work." />
67
-
68
-
### Example
69
-
70
-
Let’s output a list of the logged-in user’s addresses:
71
-
72
-
1. Create an address query with `craft.addresses()`.
73
-
2. Restrict the query to addresses owned by the current User, with the [`owner`](#owner) parameter.
74
-
3. Fetch the addresses with `.all()`.
75
-
4. Loop through the addresses using a [`{% for %}` tag](https://twig.symfony.com/doc/3.x/tags/for.html).
76
-
5. Output preformatted address details with the [`|address`](../twig/filters.md#address) filter.
77
-
78
-
```twig
79
-
{% requireLogin %}
80
-
81
-
{% set addresses = craft.addresses()
82
-
.owner(currentUser)
83
-
.all() %}
84
-
85
-
{% for addr in addresses %}
86
-
<address>{{ addr|address }}</address>
87
-
{% endfor %}
88
-
```
89
-
90
-
We’ll expand on this example in the [Managing Addresses](#managing-addresses) section.
91
-
92
-
::: warning
93
-
Protect your users’ personal information by carefully auditing queries and displaying private addresses only on pages that [require login](../twig/tags.md#requirelogin).
94
-
:::
95
-
96
-
### Parameters
97
-
98
-
Address queries support the following parameters:
99
-
100
-
<!-- This section of the page is dynamically generated! Changes to the file below may be overwritten by automated tools. -->
The [commerceguys/addressing](repo:commerceguys/addressing) library powers planet-friendly address handling and formatting, and its exhaustive repository of global address information is available to all Craft projects. If you need a list of countries, states, or provinces, for example, you can fetch them via Craft’s [Addresses](craft5:craft\services\Addresses) service, from Twig templates or PHP:
@@ -672,3 +620,55 @@ Event::on(
672
620
```
673
621
674
622
Errors are available through the same `address.getErrors()` method used in other action and [model validation examples](../../development/forms.md#models-and-validation), regardless of whether they were produced by built-in rules or ones you added.
623
+
624
+
## Querying Addresses
625
+
626
+
You can fetch addresses in your templates or PHP code using an [AddressQuery](craft5:craft\elements\db\AddressQuery).
<Seepath="../../development/element-queries.md"label="Introduction to Element Queries"description="Learn more about how element queries work." />
640
+
641
+
### Example
642
+
643
+
Let’s output a list of the logged-in user’s addresses:
644
+
645
+
1. Create an address query with `craft.addresses()`.
646
+
2. Restrict the query to addresses owned by the current User, with the [`owner`](#owner) parameter.
647
+
3. Fetch the addresses with `.all()`.
648
+
4. Loop through the addresses using a [`{% for %}` tag](https://twig.symfony.com/doc/3.x/tags/for.html).
649
+
5. Output preformatted address details with the [`|address`](../twig/filters.md#address) filter.
650
+
651
+
```twig
652
+
{% requireLogin %}
653
+
654
+
{% set addresses = craft.addresses()
655
+
.owner(currentUser)
656
+
.all() %}
657
+
658
+
{% for addr in addresses %}
659
+
<address>{{ addr|address }}</address>
660
+
{% endfor %}
661
+
```
662
+
663
+
We’ll expand on this example in the [Managing Addresses](#managing-addresses) section.
664
+
665
+
::: warning
666
+
Protect your users’ personal information by carefully auditing queries and displaying private addresses only on pages that [require login](../twig/tags.md#requirelogin).
667
+
:::
668
+
669
+
### Parameters
670
+
671
+
Address queries support the following parameters:
672
+
673
+
<!-- This section of the page is dynamically generated! Changes to the file below may be overwritten by automated tools. -->
0 commit comments