shopifyliquidliquid-layout

Shopify unique product information


I'm new to Shopify and liquid (I have programming background). What i'm currently trying to achieve is adding some unique custom information in a HTML div into the product layout.

My approach: Because I couldn't directly edit the product.liquid file (was generating the same information for all products), I decided to make a hack, so I created liquid files into the snippets by joining the product id + product. The filename would look like "11598995151product.liquid".

Into the product.liquid, I then added the following:

  {% if product.description %}<div class="col-sm-6 col-md-6 col-lg-6 col-xl-6 visible-xl" style="display:block !important">
      {% assign z = x | append: product.id | append: "product" %}
      {% include z %}
  </div>{% endif %}

Is this the best practice or can it be done easier ?


Solution

  • I slightly confused, you can't directly update the product.liquid but yet you are adding an include there. So can you or you can't?

    Here a few approaches how can you add custom unique information to products.

    1) Use an metafeild application such as https://apps.shopify.com/metafields-editor where you can set fields for each product

    2) Use shortcodes for example with this snippet https://github.com/culturekings/shopify-shortcodes

    3) Create prefixed pages, for example you have a product with a handle test-1, and you will have a page with a handle product-test-1. You perform a check for each product if there is such a page.

    4) Similiar to 3 but use a global navigation that will point to page, so that you don't have to prefix each one.

    5) Use sections. Create blocks with a product field and a richtext field (or the information you need) and set the product and information for each product as blocks. Then on the product page you check if this product handle is equal to any of the block product field.

    All of the above examples require you to modify the product.liquid page if you like for it to be unique for each product.