Answers.Body: <p>I think you're looking for the attribute function:</p>
  
  <pre><code>{% set field = attribute(addressFields, key) %}
  {{ field.label }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-15T21:27:32.897Z
Answers.LastActivityDate: 2015-12-15T21:27:32.897Z
Answers.UserDisplayName: Luke Holder
Body: <p>I need to be able to assign and output my own custom labels for the fields that are in the shipping/billing addresses during checkout in Craft Commerce. </p>
  
  <p>I've already done so on the form like so:</p>
  
  <pre><code>{% set countries = craft.commerce.countriesList %}
  {% set states = craft.commerce.statesArray %}
  {% set addressFields = {
      firstName: {
          label: 'First Name',
          required: 1,
      },
      lastName: {
          label: 'Last Name',
          required: 1,
      },
      address1: {
          label: 'Address',
          required: 1,
      },
      address2: {
          label: 'Address 2',
          required: 1,
      },
      city: {
          label: 'City',
          required: 1,
      },
      zipCode: {
          label: 'Zip Code',
          required: 1,
      },
      phone: {
          label: 'Phone',
          required: 1,
      },
      alternativePhone: {
          label: 'Alternative Phone',
          required: 1,
      },
  } %}
  
  
  {% set modelName = modelName is defined ? modelName : 'address' %}
  {% set model = address is defined ? address : null %}
  
  &lt;div class="addressBox {{ modelName }}"&gt;
      {% for key,options in addressFields %}
          &lt;div class="form-group col-md-6 {% if model and model.getErrors(key) %}has-error{% endif %}"&gt;
              &lt;label for="{{ modelName }}-{{ key }}"&gt;{{ options.label|t }}{{ options.required ? '*' : '' }}&lt;/label&gt;
              &lt;input type="text" id="{{ modelName }}-{{ key }}" class="u-full-width" name="{{ modelName }}[{{ key }}]"
                     value="{{ model ? model[key] : '' }}"&gt;
              {% if model and model.getErrors(key) %}
                  &lt;span class="flash alert-warning"&gt;{{ model.getErrors(key)|join }}&lt;/span&gt;
              {% endif %}
          &lt;/div&gt;
      {% endfor %}
  </code></pre>
  
  <p>That works like a charm. I need to however also be able to output it with my custom labels as well. Here is my currently template area, i'm not sure how i can get my custom labels in here. Please advise:</p>
  
  <pre><code>{% for address in addresses %}
       {% for key,value in address.attributes() %}
  
            {% switch key %}
  
                 {% case "id" %} {# ingore #}
                 {% case "customerId" %} {# ingore #}
  
                 {% default %}
  
                 {% if value %}
                      &lt;li&gt;
                           &lt;h3 class="cart-product-details"&gt;{{ key|title }}:
                                &lt;span class="address-option" data-key="{{ key }}" data-value="{{ value }}"&gt;
                                     {{ key == 'countryId' ? address.countryText : (key == 'stateId' ? address.stateText : value) }}
                                &lt;/span&gt;
                          &lt;/h3&gt;
                      &lt;/li&gt;
                 {% endif %}
  
            {% endswitch %}
  
       {% endfor %}
  </code></pre>
  
Tags: <form><ecommerce><plugin-craftcommerce><label><shipping>
Title: Custom Labels for Address Fields Craft Commerce
ThreadText: # Custom Labels for Address Fields Craft Commerce
  
  (Asked by: username_0 on 2015-12-15)
  
  I need to be able to assign and output my own custom labels for the fields that are in the shipping/billing addresses during checkout in Craft Commerce.
  
  I've already done so on the form like so:
  
  ```
  {% set countries = craft.commerce.countriesList %}
  {% set states = craft.commerce.statesArray %}
  {% set addressFields = {
      firstName: {
          label: 'First Name',
          required: 1,
      },
      lastName: {
          label: 'Last Name',
          required: 1,
      },
      address1: {
          label: 'Address',
          required: 1,
      },
      address2: {
          label: 'Address 2',
          required: 1,
      },
      city: {
          label: 'City',
          required: 1,
      },
      zipCode: {
          label: 'Zip Code',
          required: 1,
      },
      phone: {
          label: 'Phone',
          required: 1,
      },
      alternativePhone: {
          label: 'Alternative Phone',
          required: 1,
      },
  } %}
  
  {% set modelName = modelName is defined ? modelName : 'address' %}
  {% set model = address is defined ? address : null %}
  
  <div class="addressBox {{ modelName }}">
      {% for key,options in addressFields %}
          <div class="form-group col-md-6 {% if model and model.getErrors(key) %}has-error{% endif %}">
              <label for="{{ modelName }}-{{ key }}">{{ options.label|t }}{{ options.required ? '*' : '' }}</label>
              <input type="text" id="{{ modelName }}-{{ key }}" class="u-full-width" name="{{ modelName }}[{{ key }}]"
                     value="{{ model ? model[key] : '' }}">
              {% if model and model.getErrors(key) %}
                  <span class="flash alert-warning">{{ model.getErrors(key)|join }}</span>
              {% endif %}
          </div>
      {% endfor %}
  
  ```
  
  That works like a charm. I need to however also be able to output it with my custom labels as well. Here is my currently template area, i'm not sure how i can get my custom labels in here. Please advise:
  
  ```
  {% for address in addresses %}
       {% for key,value in address.attributes() %}
  
            {% switch key %}
  
                 {% case "id" %} {# ingore #}
                 {% case "customerId" %} {# ingore #}
  
                 {% default %}
  
                 {% if value %}
                      <li>
                           <h3 class="cart-product-details">{{ key|title }}:
                                <span class="address-option" data-key="{{ key }}" data-value="{{ value }}">
                                     {{ key == 'countryId' ? address.countryText : (key == 'stateId' ? address.stateText : value) }}
                                </span>
                          </h3>
                      </li>
                 {% endif %}
  
            {% endswitch %}
  
       {% endfor %}
  
  ```
  
  **Tags:** form, ecommerce, plugin-craftcommerce, label, shipping
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-15. Score: 2 | Accepted answer
  
  I think you're looking for the attribute function:
  
  ```
  {% set field = attribute(addressFields, key) %}
  {{ field.label }}
  
  ```
  
  
  ---
  
  