Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-10T02:39:46.843Z
Answers.Text: Yes! Thanks Luke - I wasn't sure how to set the address variable exactly.
Answers.UserDisplayName: A Herrera
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-10T02:25:41.553Z
Answers.LastActivityDate: 2016-11-10T02:25:41.553Z
Answers.UserDisplayName: Luke Holder
Body: <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>
  
Tags: <plugin-craftcommerce><ecommerce>
Title: Edit a single address in Commerce
ThreadText: # Edit a single address in Commerce
  
  (Asked by: username_0 on 2016-11-10)
  
  I've read [the docs](https://craftcommerce.com/docs/customer-address-management) 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:
  
  ```
  <a href="{{ url('account/edit-address') }}?addressId={{ address.id }}">Edit</a>
  
  ```
  
  Then on that edit-address template I have the following:
  
  ```
  {% set addressId = craft.request.getParam('addressId') %}
  
  <form method="post">
      {{ getCsrfInput() }}
      <input type="hidden" name="action" value="commerce/customerAddresses/save">
      <input type="hidden" name="redirect" value="account/address-book">
  
      {% if addressId %}
          <input type="hidden" name="address[id]" value="{{ addressId }}">
      {% endif %}
  
      <input type="text" name="address[firstName]" value="{{ address ? address[firstName] : '' }}">
      <input type="text" name="address[lastName]" value="{{ address ? address[lastName] : '' }}">
  </form>
  
  ```
  
  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 username_1 - I wasn't sure how to set the address variable exactly.  
  
  ---
  
  