Skip to content

Commit 40333b1

Browse files
committed
Relocate Address query section to end
1 parent d9a4b47 commit 40333b1

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

docs/5.x/reference/element-types/addresses.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,6 @@ Addresses can be copied and pasted between users and [addresses fields](../field
4848

4949
<See path="../../system/elements.md" hash="copying-elements" label="Copying Elements" description="Learn how to copy addresses and other elements between contexts." />
5050

51-
## Querying Addresses
52-
53-
You can fetch addresses in your templates or PHP code using an [AddressQuery](craft5:craft\elements\db\AddressQuery).
54-
55-
::: code
56-
```twig
57-
{# Create a new address query #}
58-
{% set myAddressQuery = craft.addresses() %}
59-
```
60-
```php
61-
// Create a new address query
62-
$myAddressQuery = \craft\elements\Address::find();
63-
```
64-
:::
65-
66-
<See path="../../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. -->
101-
!!!include(docs/.artifacts/cms/5.x/addresses.md)!!!
102-
10351
## Address Repository
10452

10553
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(
672620
```
673621

674622
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).
627+
628+
::: code
629+
```twig
630+
{# Create a new address query #}
631+
{% set myAddressQuery = craft.addresses() %}
632+
```
633+
```php
634+
// Create a new address query
635+
$myAddressQuery = \craft\elements\Address::find();
636+
```
637+
:::
638+
639+
<See path="../../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. -->
674+
!!!include(docs/.artifacts/cms/5.x/addresses.md)!!!

0 commit comments

Comments
 (0)