• You have created Products in the Admin

  • You have created a Product Detail View


This Tutorial will show you how to use Attributes to let Users pick Variants on the Product's automatically-generated Detail Page.

It will cover how to:

  • Find where Product layouts are stored on Code Editor

  • Develop a my_attribute_layout.liquid file

  • Allow the User to select Attribute Options before adding to Cart

Folder Structure

In SITE MANAGER/Code Editor, the folder structure for eCommerce layouts is as below:


Creating a new set of Product Layouts

To create a new set of Product layouts- create your folder at the level of "name_of_my_layout". Inside that, the folders and files should be created as shown above.

Including a Single Known Attribute on a Detail Page

If you are making a layout where you know exactly which Attribute a Product has, you can include an Attribute layout to display an Attribute with a given name.

detail/item.liquid (including a single Attribute)

{% include 'ecommerce/product_attributes', name: attribute, layout: 'demo_site_attributes', attribute_name: "Size" -%}

Looping Over Multiple Attributes

If your Products have multiple Attributes, or you want to write code which can dynamically display any Attribute given to the Product, you can use liquid to loop over all Attributes. We've recently updated this example to be much simpler and easier to use.


  1. Loop over all Attribute Options

  2. Check if the Attribute is enabled

  3. If so, include the relevant Attribute layout, dynamically filling in the "name" parameter.

Full example:

detail/item.liquid -- (looping over all Attributes linked to this Product)

{% for attribute in this.product_attributes %}
  {% if == true %}
    {% include 'ecommerce/product_attributes', name:, layout: 'demo_site_attributes' -%}
  {% endif %}
{% endfor %}

Attribute Layout Development

There is no need to create a wrapper file for Attributes, as they are already included inside an item.liquid file. Your Attribute layout can be given a name of your choice. Different Attributes for the same Product may use different Attribute layouts, e.g. "Colour" may include colour swatches.

You can output the name of the Attribute that the current Layout displays:


The following liquid outputs an array of the options that have been created for this Attribute:


You can loop over this array with the following liquid code, (where the example has the variable "option", you could choose any variable name):

{% for option in product_attribute_options -%}
  {{}} ({{this.price.currency_symbol}}{{option.price}})
{% endfor %}

To get the full benefits of Attribute functionality, including the user's choice of Attribute affecting what is added to the Cart, the data-attributes and function calls in the example should be included:

<select name="attr1" class="form-control" data-attribute-control="{{product_attribute_id}}" onchange="s_e_update_price()">
  {% for option in product_attribute_options %}
    <option value="{{}}" data-attribute-price-control="{{option.price_raw}}">
      {{}} {{this.price.currency_symbol}}{{option.price}})
  {% endfor %}

As you can see in the example, inside the loop it is possible to access the specific Attribute Option in this iteration via the "option" variable you created when setting up the loop, but you can also still access the "this" object specific to the Detail Layout that wraps around and includes the Attribute Layout. See the Product Layout Liquid Reference to see the fields available in the "this" object and those specific to Attributes and Attribute Options.

See the Product Layout Reference Doc for fields you can use throughout your Product Layouts.

Did this answer your question?