MODULES
...
eCommerce
Products

Attribute Layouts

11min
product attribute layouts allow you to customise the way that you present users with a choice of which variation of a product they want product attribute layouts allow you to customise the way that you present users with a choice of which variation of a product they want prerequisites you have created products in the admin you have created a product detail view introduction 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 layouts modules module 14 product name of my layout list wrapper liquid item liquid detail wrapper liquid item liquid product attributes my attribute layout liquid 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 steps loop over all attribute options check if the attribute is enabled 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 attribute properties enabled == true %} {% include 'ecommerce/product attributes' name attribute properties 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 {{this attribute properties name}} the following liquid outputs an array of the options that have been created for this attribute {{product attribute options}} 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 %} {{option name}} ({{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 {% for option in product attribute options %} {{option name}} {{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