<p>Are you looking for something like this? The second example will ensure an address variable exists, even if it is set to null.</p>

<p><code>{% set address = craft.commerce.customer.address(addressId) %}</code></p>

<p>or</p>

<p><code>{% set address = address is defined ? address : null %}</code></p>

<p>As for accessing the data, you would just do this:</p>

<p><code>{{ address ? address.firstName : '' }}</code></p>

<p>Another way to do it (without needing to define a null address variable) is:</p>

<p><code>{{ address.firstName ?? '' }}</code></p>

CC BY-SA 3.0
2016-11-10T02:39:46.843Z
Yes! Thanks Luke - I wasn't sure how to set the address variable exactly.
A Herrera
CC BY-SA 3.0
2016-11-10T02:25:41.553Z
2016-11-10T02:25:41.553Z
Luke Holder
<p>I've read <a href="https://craftcommerce.com/docs/customer-address-management" rel="nofollow noreferrer">the docs</a> but I can't seem to get this to work properly. I want to edit a single address on a separate page from where all addresses for a customer are listed. I have the link to the edit page, which looks like this:</p>

<pre><code>&lt;a href="{{ url('account/edit-address') }}?addressId={{ address.id }}"&gt;Edit&lt;/a&gt;
</code></pre>

<p>Then on that edit-address template I have the following:</p>

<pre><code>{% set addressId = craft.request.getParam('addressId') %}

&lt;form method="post"&gt;
    {{ getCsrfInput() }}
    &lt;input type="hidden" name="action" value="commerce/customerAddresses/save"&gt;
    &lt;input type="hidden" name="redirect" value="account/address-book"&gt;

    {% if addressId %}
        &lt;input type="hidden" name="address[id]" value="{{ addressId }}"&gt;
    {% endif %}

    &lt;input type="text" name="address[firstName]" value="{{ address ? address[firstName] : '' }}"&gt;
    &lt;input type="text" name="address[lastName]" value="{{ address ? address[lastName] : '' }}"&gt;
&lt;/form&gt;
</code></pre>

<p>That leads to a "Variable 'address' does not exist" error. I understand why I get that error but I'm not sure how to get the value field to show the address info. Having a blank form field isn't going to cut it.</p>

<plugin-craftcommerce><ecommerce>
Edit a single address in Commerce
# Edit a single address in Commerce

(Asked by: username_0 on 2016-11-10)

I've read the docs but I can't seem to get this to work properly. I want to edit a single address on a separate page from where all addresses for a customer are listed. I have the link to the edit page, which looks like this:
Edit

Then on that edit-address template I have the following:
{% set addressId = craft.request.getParam('addressId') %}


    {{ getCsrfInput() }}
    
    

    {% if addressId %}
        
    {% endif %}

    
    


That leads to a "Variable 'address' does not exist" error. I understand why I get that error but I'm not sure how to get the value field to show the address info. Having a blank form field isn't going to cut it.

**Tags:** plugin-craftcommerce, ecommerce


---

## 1 answers

### Answer by username_1 on 2016-11-10. Score: 2 | Accepted answer

Are you looking for something like this? The second example will ensure an address variable exists, even if it is set to null.

`{% set address = craft.commerce.customer.address(addressId) %}`

or

`{% set address = address is defined ? address : null %}`

As for accessing the data, you would just do this:

`{{ address ? address.firstName : '' }}`

Another way to do it (without needing to define a null address variable) is:

`{{ address.firstName ?? '' }}`

> **Comments:**
> **username_0**: Yes! Thanks Luke - I wasn't sure how to set the address variable exactly.  

---

