_customer_field partial - CrystalCommerce Liquid Documentation for Designers

_customer_field partial

Example Usage

In user_account.liquid you would add:

{% highlight html %}
          <p>
            <label for="user_email">E-Mail</label>
            <input type="text" name="user[email]" value="{{ current_user.email }}" />
          </p>
          <p>
            <label for="user_phone">Phone</label>
            <input type="text" name="user[phone]" value="{{ current_user.phone }}" />
          </p>
        
          {{ "{%" }} for customer_field in current_user.custom_fields %}
            {{ "{%" }} include 'customer_field' with customer_field %}
          {{ "{%" }} endfor %}
        
          <p>
            <input type="submit" name="submit" value="Save Changes" />
          </p>
        {% endhighlight %}

That will generate a form field for each custom field that the user has and put it after the standard form fields.

Note: there are no typos above. The partial and drop are called “customer_field” instead of “custom_field” to prevent ambiguity in filenames and drop names should we ever need to add custom fields to other areas of the application.

File: _customer_field.liquid

Default Liquid Template

<p>
  <label for="user_{{ customer_field.field_name }}">{{ customer_field.label }}</label><br/>
  <input type="text" id="user_{{ customer_field.field_name }}" name="user[{{ customer_field.field_name }}]" value="{{ customer_field.value }}" />
</p>

Default Mobile Liquid Template

<dl>
  <dt><label for="user_{{ customer_field.field_name }}">{{ customer_field.label }}</label></dt>
  <dd><input type="text" id="user_{{ customer_field.field_name }}" name="user[{{ customer_field.field_name }}]" value="{{ customer_field.value }}" /></dd>
</dl>

Drops Supported