Liquid language (MetaFields)

What is meta field ?

Metafields are a flexible way for your app to add and store additional information about a Shopify resource, such as a product, a collection, and many other owner types. The additional information stored in metafields can be almost anything related to a resource. Some examples are specifications, size charts, downloadable documents, release dates, images, or part numbers.

Merchants and other apps can retrieve and edit the data that's stored in metafields from the Shopify admin. You can also access metafields in themes using Liquid and through the Storefront API.

how it works :-

A metafield includes the following parts:

  • Namespace: A container for a group of metafields. Grouping metafields within a namespace prevents your metafields from conflicting with other metafields with the same key name.

  • Key: The name for the metafield.

  • Type: The type of data that the metafield stores.

  • Value: The data to store in the metafield. The value is always stored as a string, regardless of the metafield's type.

syntax:- {{ resource.metafields.namespace.key }}
syntax:- {{ resource.metafields.namespace.key.value }}
example:-
Type: {{ product.metafields.information.directions.type }}
Value: {{ product.metafields.information.directions.value }}

Output
Type: single_line_text_field
Value: Take with a meal.

DO YOU KNOW:-

  • The maximum number of values that can be stored in a meta field list is 128.

  • In the theme editor, you can add mximum of 200 definitions but by using code there is no limitations of add metafileds, you can add unlmited meta fields

  • List metafields enable you to store multiple values in a single metafield.(The value must be provided as a JSON array).

  • You can implement list metafields on the online store using sections and blocks.

  • 'Metafield_tag' generates an HTML element to host the metafield data. The type of element that's generated differs depending on the type of metafield.

  • There is no options in shopify to bulk upload metafield but by using 3rd part App like Metafied Guru we can bulk upload.

  • metafield is always available in its supported objects.

<!-- boolean -->
{{ product.metafields.information.seasonal | metafield_tag }}

<!-- collection_reference -->
{{ product.metafields.information.related_collection | metafield_tag }}

<!-- color -->
{{ product.metafields.details.potion_color | metafield_tag }}

<!-- date -->
{{ product.metafields.information.expiry | metafield_tag }}

<!-- date_time -->
{{ product.metafields.information.brew_date | metafield_tag }}

<!-- json -->
{{ product.metafields.information.burn_temperature | metafield_tag }}

<!-- money -->
{{ product.metafields.details.price_per_ml | metafield_tag }}

<!-- multi_line_text_field -->
{{ product.metafields.information.shipping | metafield_tag }}

<!-- number_decimal -->
{{ product.metafields.information.salinity | metafield_tag }}

<!-- number_integer -->
{{ product.metafields.information.doses_per_day | metafield_tag }}

<!-- page_reference -->
{{ product.metafields.information.dosage | metafield_tag }}

<!-- product_reference -->
{{ product.metafields.information.related_product | metafield_tag }}

<!-- rating -->
{{ product.metafields.details.rating | metafield_tag }}

<!-- single_line_text_field -->
{{ product.metafields.information.directions | metafield_tag }}

<!-- url -->
{{ product.metafields.information.health | metafield_tag }}

<!-- variant_reference -->
{{ product.metafields.information.health | metafield_tag }}


output:------------------------------>>>>>>>



<!-- boolean -->
<span class="metafield-boolean">false</span>
<!-- collection_reference -->
<a href="/collections/sale-potions" class="metafield-collection_reference">Sale potions</a>
<!-- color -->
<span class="metafield-color">#ff0000</span>
<!-- date -->
<time datetime="2040-01-01" class="metafield-date">January 1, 2040</time>
<!-- date_time -->
<time datetime="2022-06-22T13:00:00Z" class="metafield-date_time">Jun 22, 2022, 1:00 pm</time>
<!-- json -->
<script type="application/json" class="metafield-json">{"temperature":"700","unit":"degrees","scale":"Fahrenheit"}</script>
<!-- money -->
<span class="metafield-money">$0.10 CAD</span>
<!-- multi_line_text_field -->
<span class="metafield-multi_line_text_field">All health potions are made to order, so it might take up to 2 weeks before your order can be shipped.<br />
<br />
Thanks for your patience!</span>
<!-- number_decimal -->
<span class="metafield-number_decimal">8.4</span>
<!-- number_integer -->
<span class="metafield-number_integer">3</span>
<!-- page_reference -->
<a href="/pages/potion-dosages" class="metafield-page_reference">Potion dosages</a>
<!-- product_reference -->
<a href="/products/dried-chamomile" class="metafield-product_reference">Dried chamomile</a>
<!-- rating -->
<span class="metafield-rating">4.5</span>
<!-- single_line_text_field -->
<span class="metafield-single_line_text_field">Take with a meal.</span>
<!-- url -->
<a href="https://www.canada.ca/en/health-canada/services/food-nutrition/legislation-guidelines/acts-regulations/canada-food-drugs.html" class="metafield-url">www.canada.ca/en/health-canada/services/food-nutrition/legislation-guidelines/acts-regulations/canada-food-drugs.html</a>
<!-- variant_reference -->
<a href="https://www.canada.ca/en/health-canada/services/food-nutrition/legislation-guidelines/acts-regulations/canada-food-drugs.html" class="metafield-url">www.canada.ca/en/health-canada/services/food-nutrition/legislation-guidelines/acts-regulations/canada-food-drugs.html</a>
Important metafield resources :--

[meta field reference](https://shopify.dev/apps/metafields)

[metafiled access types](https://shopify.dev/api/liquid/objects/metafield#metafield-access-metafields)

[metafield types](https://shopify.dev/apps/metafields/types)

[metafield tag(very imp)](https://shopify.dev/api/liquid/filters/metafield_tag)

\=============================================================